Skip to content

Instantly share code, notes, and snippets.

@clohr
Created August 6, 2015 23:40
Show Gist options
  • Save clohr/3aa037cd7b77f2ca3459 to your computer and use it in GitHub Desktop.
Save clohr/3aa037cd7b77f2ca3459 to your computer and use it in GitHub Desktop.
Find DOM Element Parent Node
'use strict';
module.exports = function findParent(childElement, parentNodeSelector) {
while (childElement && childElement.parentNode !== document) {
if (childElement.hasAttribute(parentNodeSelector) || childElement.className.indexOf(parentNodeSelector) > -1) {
return childElement;
}
childElement = childElement.parentNode;
}
return null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment