Skip to content

Instantly share code, notes, and snippets.

@toruta39
Created July 17, 2012 12:29
Show Gist options
  • Save toruta39/3129162 to your computer and use it in GitHub Desktop.
Save toruta39/3129162 to your computer and use it in GitHub Desktop.
Another way to use iterative to check if otherNode is a child element of refNode
//Inspired by jQuery, link: http://www.zhangsuoyong.com/?p=111
function checkParent(refNode, otherNode) {
var parent = otherNode.parentNode;
try {
while ( parent && parent !== refNode ) {
parent = parent.parentNode;
}
return (parent !== refNode);
} catch(e) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment