Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button click event not firing in jQuery

This is the method:

$(document).ready(function () {
    $('btnDelete1').click(function () {
        alert("something");
    })
});

And this is the code for the button:

<input type="submit" value="Delete Role" disabled="disabled" id="btnDelete1"/>

But whenever I click the button, the alert isn't happening. Why is this?

like image 444
dfgj fghjk Avatar asked Nov 28 '25 17:11

dfgj fghjk


2 Answers

The problem isn't connected with MVC anyway, you missed # in Jquery selector only.

$(document).ready(function () {
    $('#btnDelete1').click(function () {
        alert("something");
    });
});

EDIT:

And as mentioned Jeffrey, you forget ; too

like image 135
Chuck Norris Avatar answered Nov 30 '25 05:11

Chuck Norris


Your selector is wrong

It should be

$(document).ready(function () {
    $('#btnDelete1').click(function () {
        alert("something");
    });
});
like image 28
tobias86 Avatar answered Nov 30 '25 05:11

tobias86



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!