开发者

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

开发者 https://www.devze.com 2023-01-28 17:27 出处:网络
Assuming I create something like: <div> <p myAttribute=\'Hello\'>Text</p> .. </div>

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 d开发者_JAVA百科o this?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消