jQuery - How to match an element has attribute a or attribute b

时间秒杀一切 提交于 2019-12-04 04:07:53

问题


How to write a jquery selector to match an element has attribute a or attribute b. It must match three elements below

<a a="123" b="345"></a>
<a a="123"></a>
<a b="345"></a>

回答1:


You can use a multiple selector (,) with the attribute-equals selector (or any other selectors), for example:

$("a[a=123], a[b=345]")

You can test it out here.




回答2:


Or generally for mere presence of attribute

$("a[a], a[b]")



回答3:


Try this

$('a[b="345"],a[a=123] ')

See the jQuery Multiple selector docs.



来源:https://stackoverflow.com/questions/3890265/jquery-how-to-match-an-element-has-attribute-a-or-attribute-b

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!