Last active
February 20, 2020 07:43
-
-
Save KaKi87/27f182e731ac30282619754aa7df2fbc to your computer and use it in GitHub Desktop.
Get all parents of HTML element
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
const getParents = element => { | |
const parents = []; | |
for (; element && element !== document; element = element.parentElement){ | |
parents.push(element); | |
} | |
return parents; | |
}; | |
/* | |
Source : https://gomakethings.com/how-to-get-all-parent-elements-with-vanilla-javascript/ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment