Reputation: 4376
Can somebody help me with the syntax of what I'm trying to do here?
jQuery('(div[data-positiontype="3"]) && (div[data-positiontitle*="test"] || div[data-positiondesc*='test'])')
Basically I need the ability to select all divs that have a particular "data-positiontype" attribute and a token in either the "data-positiontitle" attribute or the "data-positiondesc" attribute.
Upvotes: 5
Views: 113
Reputation: 700910
You stack the selectors together to find elements that matches both, and use the ,
combinator between selectors:
jQuery('div[data-positiontype="3"][data-positiontitle*="test"],div[data-positiontype="3"][data-positiondesc*="test"]')
Upvotes: 2
Reputation: 255155
$('div[data-positiontype="3"]').filter('[data-positiontitle*="test"], [data-positiondesc*="test"]').
or the straightforward:
$('div[data-positiontype="3"][data-positiontitle*="test"], div[data-positiontype="3"][data-positiondesc*="test"]').
Upvotes: 10