jquery - Using javascript, how to select an li relative to a specific other li -
given following html list:
<ul> ... <li> <li> // <-- item selected <li> <li class='current'> <li> <li> <li> ... </ul>
how select li 2 instances ahead of li class current? pure javascript or jquery solution great!
making more generic, i.e if want select li possibly(2nd or 3rd or ever instance appears prior selector), try
$('li.current').prevall(':eq(' + n-1 + ')');
here n instance # talking (since 0 based index). in case be:
$('li.current').prevall(':eq(1)');
do remember prevall returns elements in order starting selector, can provide index of element position in prevall
eq
selector.
Comments
Post a Comment