Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does jQuery support OR in selectors?

I am wondering if jQuery can do something like this 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 the last row which is either row_c or row_d however the catch is that row_c or row_d is inserted in between another set of alternating rows row_a and row_b so 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 the | or operator in jQuery? Or is there something similar?

like image 441
Paul Avatar asked Jun 02 '11 20:06

Paul


People also ask

How many selectors are there in jQuery?

Two selectors: visible and: hidden are also available in JQuery.

Are all CSS selectors compatible with jQuery?

Starting from jQuery 1.9, virtually all selectors in the level 3 standard are supported by Sizzle (its underlying selector library), with the following exceptions: jQuery cannot select any pseudo-elements as they are CSS-based abstractions of the document tree that can't be expressed through the DOM.


1 Answers

Yes, I believe it does, but in a CSS manner (jsfiddle as a proof):

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

EDIT:

If you wanted to match only last element having class row_c or row_d, you may wish to use something like that (jsfiddle as a proof):

$(".row_c, .row_d").last().css("color","red");
like image 145
Tadeck Avatar answered Nov 03 '22 14:11

Tadeck