开发者

What is the best way to select an element if the element's index is over 3?

Pseudo Code

$("#cool ul li.active:eq( > 3)") { // selector if the active li is over 3
     $('#cool ul').animate({right: '+=984'},0);
};

What is the 开发者_JAVA百科best way to select if the li is over 3?


:gt selector

if ($("#cool li:gt(3)").hasClass('active')) { 
     $('#cool ul').animate({right: '+=984'},0);
};

EDIT: Had it correct the first time, thought I had it wrong and made it incorrect, should be back to correct again :P


if($("#cool ul li:gt(2)").filter('.active').length === 1) {
  $('#cool ul').animate({right: '+=984'},0);
};

EDIT: Updated code to assume 1 .active li
EDIT 2: Momentarily forgot :gt() uses a 0 based index

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜