Skip to content

Instantly share code, notes, and snippets.

@cladley
Created February 21, 2020 09:03
Show Gist options
  • Save cladley/645a19a04e37b04fee70b4fd8c494207 to your computer and use it in GitHub Desktop.
Save cladley/645a19a04e37b04fee70b4fd8c494207 to your computer and use it in GitHub Desktop.
Check if dom node is contained in parent node
/**
* Determines if html element is
* contained within other html element
*
* @param {HTMLElement} refNode
* @param {HTMLElement} otherNode
*/
const isParent = (refNode, otherNode) => {
var parent = otherNode.parentNode;
do {
if (refNode == parent) {
return true;
} else {
parent = parent.parentNode;
}
} while (parent);
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment