user2733521
user2733521

Reputation: 449

JQuery multiple AND OR selector

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

Answers (3)

GrafiCode
GrafiCode

Reputation: 3374

You possible outcomes are:

  • .a.c
  • .a.d
  • .b.c
  • .b.d

hence:

$('.a.c, .a.d, .b.c, .b.d')

Upvotes: 2

jfriend00
jfriend00

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

Tyler Crompton
Tyler Crompton

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

Related Questions