I have a disabled='disabled'
attribute on an <a>
tag. How do I test to see if this attribute is on my tag using jquery? The following code returns undefined
. I can see the disabled
attribute on the tag in firebug and all other attributes on the anchor return successfully using the same syntax. I realize disabled
is a custom attribute for an <a>
tag.
$('#anchorID').attr('disabled');
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With