Best way to get child nodes in JavaScript
The contains all nodes, including text nodes consisting entirely of whitespace
The cross browser way to do is to use to get , then make an array of all nodes with ELEMENT_NODE.
/**
* Return direct children elements.
* * @param {HTMLElement}
* @return {Array}
*/
function elementChildren (el){
var childNodes = el.childNodes, children =[], i = childNodes.length;
while(i--){
if(childNodes[i].nodeType ==1){
children.unshift(childNodes[i]);
}
}
return children;
}
Thanks