Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Retrieving all DOM descendants

First observation of the day: IE 5 for Windows doesn’t understand element.getElementsByTagName('*') to retrieve all descendants of an element in the DOM. element.all has the desired effect for that browser. So to retrieve all descendants in a way that will work on standards compliant browsers plus IE 5, the following seems to be the best bet:

var elements = element.all ? element.all : element.getElementsByTagName('*');

This is Retrieving all DOM descendants by Simon Willison, posted on 27th March 2003.

View blog reactions

Next: Attribute selectors now supported

Previous: getElementsBySelector()

2 comments

  1. That'll throw a warning with strict warnings enabled in mozilla. Use object detection instead: var elements=typeof element.all!='undefined'?element.all:element.getEl ementsByTagName('*');

    liorean - 27th March 2003 15:03 - #

  2. Retrieving all DOM descendants is good, but how do i determine the size (say width, for example), for all DOM descendants?

    Manav - 14th April 2004 11:34 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2003/03/27/retrievingAllDomDescendants

A django site