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
精彩评论