Your selector $("button") is wrong. If you have an HTML
id
attribute with the value "button",
id="button"
, you need to use an
id selector $("#button")
:
http://api.jquery.com/id-selector/[
^].
The selector you uses can be used only if you have only one element "button", no matter what attributes it has, which makes this selector not really robust and potentially error-prone:
http://api.jquery.com/element-selector/[
^].
It's always better to rely on unique element position in the DOM hierarchy or unique attribute value (with "id" being the best because it requires uniqueness). Please see:
http://api.jquery.com/category/selectors/hierarchy-selectors/[
^],
http://api.jquery.com/category/selectors/attribute-selectors/[
^],
http://api.jquery.com/category/selectors/[
^].
In ASP.NET code, to make sure the HTML id attribute gets required value, use
System.Web.UI.Control.ClientID
and make sure you use correct
ClientIDMode
:
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid%28v=vs.110%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.web.ui.clientidmode%28v=vs.110%29.aspx[
^].
Also, make sure that your jQuery script is put in the
<body>
HTML element, not
<head>
.
—SA