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.
+1
A:
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.
Tim Down
2010-02-01 09:31:35