Chez Xavier

Home / Traversing elements


Rue du Faubourg du Temple, in Paris: one old broken mannequin face, in front of a clothes shop. The quarter is particularly living, cheep and popular. See on Flickr

Back in January, I published the French translation of the Element Traversal Specification recommendation. Along with it, I have also made tonight a fast jQuery implementation of the ElementTraversal API.

What is Element Traversal?

Shortly said, the Element Traversal is an interface that exposes a set of new attributes on DOM Elements. The Element Traversal interface focuses on Element nodes and ignores every nodes of a DOM tree that are not of that type, which is indeed what the (web) developers usually require (a developper who parses a XML DOM is more often interested in the elements nodes than in the comments nodes. See the Mozilla Developer Center for a list of the available nodeTypes).

Until now, the DOM trees were exposed using the traditional DOM Level 1 Core API, which provides attributes like firstChild, lastChild, etc. Walking through the elements of one DOM tree always required to check if the nodes were of type "Element" (and not "Text", for instance) and, check after check, a lot of computation time (and also developers' hair) was lost, due to the lack of a specialized programmation interface.

Performant javascript frameworks, like jQuery, for example, have reduced this complexity and hide it to the web developer. But the high-level javascript implementation made bu jQuery of an API similar to Element Traversal wll always be slower than a native browser implementation. For User-Agent vendors, implementing the Element Traversal interface could therefore lead to better script performances.

Not all of the market browsers support Element Traversal. Firefox 3.1, 3.5 and Opera 10, the upcoming versions of the famous browsers do, but neither Firefox 3.0 nor Safari or IE7 support the specification.