[thelist] DOM: previousSibling and LI tags
Christian Heilmann
codepo8 at gmail.com
Fri Jan 20 04:12:06 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.
<shamelessPlug>That is why it is part of my upcoming book</shamelessPlug>
I will include this little tool in a DOMhelp object to ease some of
this work. it is a bit like re-inventing yet another library, but
might help.
--
Chris Heilmann
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/
Binaries: http://www.onlinetools.org/
More information about the thelist
mailing list