开发者

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

开发者 https://www.devze.com 2023-03-09 06:08 出处:网络
Pseudo Code $(\"#cool ul li.active:eq( > 3)\") { // selector if the active li is over 3 $(\'#cool ul\').animate({right: \'+=984\'},0);

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

精彩评论

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