JamesBrownIsDead
JamesBrownIsDead

Reputation: 821

MooTools: getChildren() INCLUDING text nodes?

I'd like to get all the children of an element, including text nodes. How can I do this in MooTools? The documentation at mootools.net explicitly says that getChildren() excludes text nodes.

Upvotes: 1

Views: 1440

Answers (1)

Tim Down
Tim Down

Reputation: 324597

You could use the standard childNodes DOM property, which works in all the major desktop browsers:

var el = document.getElementById("someElement");
var children = el.childNodes;
for (var i = 0, len = children.length; i < len; ++i) {
    alert( "Is text node: " + (children[i].nodeType == 3) );
}

Note that childNodes is not an array and therefore doesn't have Array's methods, but has a length property and allows you to access its members via numerical properties. Also, IE does not include whitespace text nodes whereas other browsers do.

Upvotes: 5

Related Questions