Skip to content

Instantly share code, notes, and snippets.

@VitorLuizC
Created September 18, 2017 03:17
Show Gist options
  • Save VitorLuizC/498ffc12b499d6e578510278c1826b44 to your computer and use it in GitHub Desktop.
Save VitorLuizC/498ffc12b499d6e578510278c1826b44 to your computer and use it in GitHub Desktop.
Get all element parents.
/**
* 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