Created
June 27, 2017 21:01
-
-
Save jmlavoier/567b391679fb5ccddb174df7431a8ca1 to your computer and use it in GitHub Desktop.
08-challenge-code
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 p = document.querySelector('.p1'); | |
const parents = function (el) { | |
let arrayElements = []; | |
let currentEl = el; | |
return function findParentByTagName(tn) { | |
currentEl = currentEl.parentElement; | |
if (!currentEl) return arrayElements; | |
if (currentEl.tagName === tn) { | |
arrayElements.push(currentEl); | |
} | |
return findParentByTagName(tn); | |
} | |
} | |
//Parents | |
const getParentsByTagName = parents(p); | |
console.log(getParentsByTagName('DIV')); // [div#cont.content, div, div] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment