假设我创建了类似的东西:
<div>
<p myAttribute='Hello'>Text</p>
..
</div>
然后我想在我的页面上找到所有具有myAttribute的元素,无论它们是什么。我该怎么做?
答案 0 :(得分:10)
您可以使用has-attribute selector,例如:
$("[myAttribute]")
要使用该特定值获取具有该属性的元素,请使用attribute-equals selector,如下所示:
$("[myAttribute='Hello']")
You can find the full list of Attribute Selectors available here