开发者

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

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


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");


Your mixing your logic concepts a bit there. To do a simple or, you just separate your selectors with a comma:

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

An and would be to combine them:

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

But I don't think that's what you are looking for. You are looking for a specific pair of rows and want to act upon the second item.

I'd do something like this:

$(".row_d").next(".row_c").dosomething


Just use comma as separator for different selectors:

$(".row_c ~ .row_d", ".row_d ~ .row_c").css("color","red");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜