[jQuery] How do I select the previous and next sibling of a particular type

[jQuery] How do I select the previous and next sibling of a particular type

for this to work the same in most browsers you will need to format
your HTML like so
<ul>
    <li id="a1">Item 1</li>
    <li id="a2">Item 2</li>
    <li>
        <ul>
            <li id="b1">Sub Item 1</li>
            <li id="b2">Sub Item 2</li>
        </ul>
    </li>
    <li id="a3">Item 3</li>
</ul>
.fn.prevSib = function(i, f) {
if(typeof i == "function") {
f = i;
i = 0;
}
var __next = this[i].previousSibling;
while( __next.nodeType != 1) {
__next = __next.previousSibling;
}
f(__next);
return this;
}
$.fn.nextSib = function(i, f) {
if(typeof i == "function") {
f = i;
i = 0;
}
i = i || 0;
var __next = this[i].nextSibling;
while( __next.nodeType != 1) {
__next = __next.nextSibling;
}
f(__next);
return this;
}
$(document).ready(function() {
$("#a2").click(function(event) {
var f = function(n) {
if(n) {
var jq = $(n);
jq.css("display") == "none" ? jq.show() : jq.hide();
}
};
$(this).prevSib(f).nextSib(f);
});
});
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/