Skip to content

Instantly share code, notes, and snippets.

@srph
Created March 6, 2019 06:38
Show Gist options
  • Save srph/a7e3ce7ff6109e6efcb767e10ae60de3 to your computer and use it in GitHub Desktop.
Save srph/a7e3ce7ff6109e6efcb767e10ae60de3 to your computer and use it in GitHub Desktop.
JS: Check if an element is under an anchor element
/**
* Check if an element is under an anchor element
*/
function isDescendantOfAnchor(element) {
do {
if (element.tagName === 'A') {
return true
}
} while(element = element.parentNode)
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment