How is jquery used to check for the 'disabled' attribute on an <a> tag? How is jquery used to check for the 'disabled' attribute on an <a> tag? jquery jquery

How is jquery used to check for the 'disabled' attribute on an <a> tag?


Try

$('#anchorID').is('[disabled=disabled]')

Will return true if disabled="disabled" is an attribute for the element.


The new and improved way is to use jQuery's prop() function: http://api.jquery.com/prop/#prop1

$('#anchorID').prop("disabled");

The difference between attributes and properties can be important in specific situations. Before jQuery 1.6, the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior. As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.


Try:

$('#anchorID').prop("disabled");

See:

http://api.jquery.com/prop/#prop1

Updated: +1 to Ayman Safadi's answer.