Does jQuery support OR in selectors?

I am wondering if jQuery can do something similar or is there another way to do this?

$(".row_c:last|.row_d:last").css("color","red"); 

I have alternating rows that I want to find in the last row, which is either row_c or row_d, however the trick is that row_c or row_d are inserted between another set of alternating rows row_a and row_b to illustrate:

  • row_a
  • row_b
  • row_c
  • row_d
  • row_c <- need to find this
  • row_a
  • row_b

OR

  • row_a
  • row_b
  • row_c
  • row_d <- need to find this
  • row_a
  • row_b

can we use | or operator in jQuery? Or is there something similar?

+7
source share
3 answers

Yes, I believe it is, but in CSS style ( jsfiddle as proof):

 $(".row_c:last, .row_d:last").css("color","red"); 

EDIT:

If you want to combine only the last element with the row_c or row_d , you can use something like this ( jsfiddle as proof):

 $(".row_c, .row_d").last().css("color","red"); 
+8
source

Just use a comma as a separator for different selectors:

 $(".row_c ~ .row_d", ".row_d ~ .row_c").css("color","red"); 
+1
source

Your mix of logical concepts is a bit. To make simple or , you simply separate your selectors with a comma:

 $(".this, .orThat") // looks for items with one or the other (or both) classes 

An and would consist of combining them:

 $(".thisClass.andThisClass") // looks for an item with both classes 

But I do not think what you are looking for. You are looking for a specific pair of lines and want to act on the second element.

I would do something like this:

 $(".row_d").next(".row_c").dosomething 
+1
source

All Articles