[jQuery] How do I select the previous and next sibling of a particular type
Hello List,
How do I select the immediately preceding or following sibling of a particular type.
For example:
<ul>
<li id="a1">
<li id="a2">
<ul>
<li id="b1">
<li id="b2">
< /ul>
<li id="a3">
</ul>
I would like to be able to click on li#a2 and have an action occur on the following <ul> and the previous <li> without applying it to the other siblings. Neither CSS or XPath notation as implemented in jQuery support this - as far as I can tell from the jQuery source.
I have tried something like (pseudo code):
$("ul li").click(function(){
var self = this;
$("+ ul",self).toggle(); //for FireFox
$("> ul",self).toggle(); // for IE6 (different than Firefox)
});
This does work in firefox. It works oddly in IE, especially when there is more than one level in the list tree. (I think this is actually an error in the IE6 CSS implementation... Nope, never see any of those!)
I would rather use something more like (really pseudo code):
$("ul li").click(function(){
$(this.nextSibling("ul")).toggle();
});
Thanks in advance,
Jeremiah
<a href="mailto:knochej@geo.orst.edu">knochej@geo.orst.edu</a>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/