jQuery – How to select by attribute

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"]');

Leave a Comment