JQuery move issue
I have a potentially infinitely nested tree ol > li
considering whether in a tree, I need to apply some function to all others li
below given li
except the current one ol
. As an example:
eg:
<ol>
<li>
Do not apply to me
<ol>
<li>Do not apply to me</li>
<li>Do not apply to me</li>
</ol>
</li>
<li>
Do not apply to me
<ol>
<li id='given'>I am the "given" li</li> <------------- you are here
<li>Do not apply to me</li>
<li>
Do not apply to me
<ol>
<li>Do not apply to me</li>
<li>Do not apply to me</li>
</ol>
</li>
</ol>
</li>
<li>
Apply to me
</li>
<li>
Apply to me
<ol>
<li>Apply to me</li>
<li>
Apply to me
<ol>
<li>Apply to me</li>
<li>Apply to me</li>
</ol>
</li>
</ol>
</li>
</ol>
What's the most elegant way to achieve this?
thanks
+1
a source to share
2 answers
@ Gordon's answer will work with the given example, but if there is another OL right after OL that contains #given it won't work.
$("#given").parents("ol").nextAll("ol").find("li").each(function() {
// function
});
$("#given").parents("li").nextAll("li").find("li").andSelf().each(function() {
//function
});
This will work, but perhaps a more elegant way to accomplish it.
+1
a source to share