Created
September 18, 2017 03:17
-
-
Save VitorLuizC/498ffc12b499d6e578510278c1826b44 to your computer and use it in GitHub Desktop.
Get all element parents.
This file contains hidden or 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
/** | |
* Get all element's parent. | |
* @param {Element} element | |
* @returns {Element[]} | |
*/ | |
const getParents = (element) => { | |
const parent = element.parentElement; | |
const parents = parent ? [ parent, ...getParents(parent) ] : []; | |
return parents; | |
}; | |
export default getParents; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment