Skip to content

Instantly share code, notes, and snippets.

@MoOx
Created March 14, 2013 09:41
Show Gist options
  • Save MoOx/5160070 to your computer and use it in GitHub Desktop.
Save MoOx/5160070 to your computer and use it in GitHub Desktop.
get real child nodes
function getRealFirstChild(el){
var firstChild = el.firstChild;
// skip TextNodes
while(firstChild !== null && firstChild.nodeType === 3) {
firstChild = firstChild.nextSibling;
}
return firstChild;
}
function getRealChilds(el){
var child = el.firstChild;
var childs = [];
// skip TextNodes
while(child.nextSibling) {
child = child.nextSibling;
if (child.nextSibling.nodeType === 3) {
childs.push(child);
}
}
return childs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment