JQuery - How to combine an element with attribute a or attribute b

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

<a a="123" b="345"></a>
<a a="123"></a>
<a b="345"></a>
+3
source share
3 answers

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

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

You can check it out here .

+8
source

Or generally for the mere presence of an attribute

$("a[a], a[b]")
+10
source

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

jQuery Multiple selector docs.

+5

Source: https://habr.com/ru/post/1768609/


All Articles