I have a list:
<ul>
<li class="myclass">...</li>
<l开发者_JAVA技巧i class="myclass">...</li>
<li class="myclass">...</li>
<li id="control">...</li>
<li class="myclass">...</li>
<li class="myclass">...</li>
<li class="myclass">...</li>
</ul>
How can I select all li
elements after li[id="control"]
?
li
'sThere's a .nextAll()
which will get all siblings after a particular element selection, like this:
$("#control").nextAll();
You can try it out here
In this case the siblings are <li>
elements, so it'll select all of them on the same level (not child <li>
s beneath, if they exist).
If you want a single selector, I think you can use $('#control ~ li')
. The "~" connector (is "connector" the right word? "operator" maybe?) is like "+", but it selects all following siblings and not just the first one.
Sometimes it's nice to be able to do things with a single selector string, because you may want to organize selectors and actions in a data structure. However, it's quite often the case that doing explicit jQuery function calls in a chain (as in @Nick's answer with ".nextAll()") is faster than letting the selection engine parse and evaluate a fancy selector string.
精彩评论