jQuery - How to select by attribute
Solution 1:
Here’s how to select all those elements:
$('[disabled_onclick="true"]');
Since true
is a valid unquoted attribute value in CSS, you could even omit the quotes:
$('[disabled_onclick=true]');
If you care about valid HTML you should consider using a custom data-*
attribute instead though.
<input id="b_1" type="submit" disabled_onclick="true">
<!-- …becomes… -->
<input id="b_1" type="submit" data-disabled-onclick="true">
That way it’s valid HTML, and you’ll still be able to select it as follows:
$('[data-disabled-onclick="true"]');
Solution 2:
try this
$('[disabled_onclick="true"]')
Solution 3:
$('input[disabled_onclick="true"]');
See http://api.jquery.com/attribute-equals-selector/
In the above line, you'd only query for input nodes
, you can omit the input
which would then query over all nodes in your entire markup (which is probably kind of slow'ish).
$('[disabled_onclick="true"]');