mix mix - 10 months ago 53
CSS Question

Find HTML Element that has Specific Attribute Using jQuery

How can I target an HTML element that has a specific attribute, but when that attribute has no value (well, whether it has a value or not). I've found others asking similar questions about elements with attribute values but not based on existence of the attribute itself.

For example, with this HTML:

<div id="id1">
<div class="c1"></div>
<div class="c2" an-attribute ></div>
<div class="c3"></div>

How might I go about finding the
that has the attribute
? I can't count on it being in a particular location related to the other
but can count on it being in


Try this.

$('#id1 div[an-attribute]');