Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery, is there a way to select all elements on the page with a specific attribute?

Tags:

jquery

Assuming I create something like:

<div>
<p myAttribute='Hello'>Text</p>
..
</div>

I then want to find on my page, all elements that have myAttribute, regardless of what they are. How do I do this?

like image 312
NibblyPig Avatar asked Dec 19 '25 04:12

NibblyPig


1 Answers

You can use the has-attribute selector, for example:

$("[myAttribute]")

To get elements with that attribute with that specific value, use the attribute-equals selector, like this:

$("[myAttribute='Hello']")

You can find the full list of Attribute Selectors available here.

like image 92
Nick Craver Avatar answered Dec 20 '25 20:12

Nick Craver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!