et.js, Element Traversal for everyone

et.js implements the W3C Recommendation Element Traversal, published on December 22, 2008, using general functions instead of attributes. If the W3C Recommendation is supported in your user agent, it takes advantage of it, otherwise it does it the old way using DOM Level 1 methods. It is intended for the Web developers who can't afford to assume that the Web supports Element Traversal or ECMAScript 3.1 getter/setter.

Add the following line inside the HEAD element in your HTML page:

<script type="text/javascript" src=""></script>

(Or better, save the resources of W3C and host your own copy of the file)

You can then use the following functions:

   Element        firstElementChild(myElement);
   Element        lastElementChild(myElement);
   Element        previousElementSibling(myElement);
   Element        nextElementSibling(myElement);
   Number         childElementCount(myElement);

Previous Sibling (H2)

Text in between.

This is the firstElementChild (SPAN) and the lastElementChild (U) and childElementCount is 3.

Text in between.

Next Sibling (H4)

Does it work for you?

Philippe Le Hégaret

$Date: 2008/12/23 21:58:44 $