dom-tools
Version:
A tiny collection of DOM helpers for IE8+.
33 lines (29 loc) • 773 B
JavaScript
// IE8+
//
// Returns an Array of all children Element nodes, excluding comment/text
// nodes, for "node"
var canUseDOM = require('./canUseDOM');
var children = function(){}; // noop if not working with DOM
if (canUseDOM) {
children = (function(){
if (document.children) {
return function(node) {
/// convert HTMLCollection into an Array
return Array.prototype.slice.call( node.children );
}
} else {
return function(node) {
var children = [];
var nodes = node.childNodes, n, i;
for (i = 0; i < nodes.length; i++) {
n = nodes[i];
if (n.nodeType === 1) {
children.push(n);
}
}
return children;
}
}
})();
}
module.exports = children;