Created
February 21, 2020 09:03
-
-
Save cladley/645a19a04e37b04fee70b4fd8c494207 to your computer and use it in GitHub Desktop.
Check if dom node is contained in parent node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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