complez
complez

Reputation: 8352

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

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>

Upvotes: 3

Views: 3290

Answers (3)

NoxArt
NoxArt

Reputation: 361

Or generally for mere presence of attribute

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

Upvotes: 9

Gadonski
Gadonski

Reputation: 3330

Try this

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

See the jQuery Multiple selector docs.

Upvotes: 5

Nick Craver
Nick Craver

Reputation: 630637

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.

Upvotes: 8

Related Questions