Last active
February 4, 2020 23:00
-
-
Save shanelonergan/20f2541c04680574ff11a1eb93c0a73e to your computer and use it in GitHub Desktop.
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
function getElementsByClassName2(classNameStr) { | |
function checkChildren(child) { | |
// check if the child has a matching class. If so, push the the elements array | |
if (child.classList.contains(classNameStr)) { | |
elements.push(child) | |
} | |
// check if that child has children of its own. If so, call checkChildren one each child | |
if (child.children) { | |
const children = child.children | |
children.forEach(checkChildren) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment