Reputation: 449
I need to select HTML DOM elements with multiple selectors.For example, I would like to select all dom that have classes A or B and classes D or C.
Litteraly :
((A OR B) AND (C OR D))
How can i do that in JQuery ?
I already tried this with no success:
$([.A,.B][.C,.D])
Any help ?
Upvotes: 1
Views: 349
Reputation: 3374
You possible outcomes are:
hence:
$('.a.c, .a.d, .b.c, .b.d')
Upvotes: 2
Reputation: 707406
You could use a compound statement where you get all the items that meet the first criteria then filter that out to just the items that meet the second criteria. This is a bit more scalable if there are lots of possible permutations.
$(".A, .B").filter(".C, .D");
Upvotes: 4
Reputation: 12662
If it's truly that simply, you could just do the Cartesian product and list each possibility:
$('.A.C, .A.D, .B.C, .B.D');
Upvotes: 3