[thelist] DOM: previousSibling and LI tags
ben morrison
morrison.ben at gmail.com
Fri Jan 20 04:05:29 CST 2006
> No, just understanding the DOM and safely use it. Test the type of the
> node and apply your bits and bobs then. You can use this replacement
> function for example to really reach the previous LI.
>
> function realPreviousSibling(node){
> var tempNode=node.previousSibling;
> while(tempNode.nodeType!=1){
> tempNode=tempNode.previousSibling;
> }
> return tempNode;
> }
>
> realPreviousSibling(this) will now return the first previous element
> sibling, regardless of browser.
>
> HTH
> Chris
That works perfectly, thankyou. The more javascript i learn, the more
i realise you really have to test for everything - which is a good
coding practice.
ben
More information about the thelist
mailing list