JQuery selector with parameters "and" and "or"

Can someone 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 specific attribute "data-positiontype" and a token in the attribute "data-positiontitle" or the attribute "data-positiondesc".

+5
source share
2 answers
$('div[data-positiontype="3"]').filter('[data-positiontitle*="test"], [data-positiondesc*="test"]').

or simply:

$('div[data-positiontype="3"][data-positiontitle*="test"], div[data-positiontype="3"][data-positiondesc*="test"]').
+10
source

You add selectors together to find elements that match both, and use a combinator ,between the selectors:

jQuery('div[data-positiontype="3"][data-positiontitle*="test"],div[data-positiontype="3"][data-positiondesc*="test"]')
+2
source

All Articles