Last active
August 28, 2016 06:39
-
-
Save ajliv/a6f99c33714e720aa9a82538c1e40080 to your computer and use it in GitHub Desktop.
Determine if event target is a descendant of a DOM 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
/** | |
* Determine if event target is a descendant of a DOM node | |
* @param {Object} event - The event object | |
* @param {Element} parent - The DOM node to check if event target is equal to or a descendant of | |
* @return {Boolean} | |
*/ | |
function targetIsDescendant(event, parent) { | |
var node = event.target || null; | |
while (node !== null) { | |
if (node === parent) return true; | |
node = node.parentNode; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment