On my web page I have a button, and some JQuery code. The problem is that when I click the button, the JQuery code is not executed. Clicking the button still does a postback, and seems to ignore the JQuery code.
Here is my button:
<button id="btnCancel" class="button" runat="server" ><span>Cancel</span></button>
Here is my JQuery Code:
$(document).ready(function () {
$('#btnCancel').click(function () {
alert('hello');
});
});
what I would like to achieve is that when the button is clicked, a message must be displayed showing “Hello”.
Am I missing something here?
What people have said here will work. Make sure you have put all the pieces together.
Add jQuery
Add your code
I added a “return false;” in there to keep the page from posting back, if you only wanted the javascript to run.