Last active
March 8, 2020 17:00
-
-
Save iankit3/7a6bd9dae60a419469dc443e401f0dca to your computer and use it in GitHub Desktop.
document.getElementsByClassName
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
// Just to test, Run it on https://www.hackerearth.com/practice/data-structures/hash-tables/basics-of-hash-tables/tutorial/ | |
var root = document.getRootNode(); | |
var count = 0; | |
var list = []; | |
function search(head) { | |
if (head.classList && head.classList.contains("light")) { | |
count++; | |
list.push(head); | |
} | |
if (head.hasChildNodes()) { | |
[].slice | |
.call(head.childNodes) | |
.filter(e => e.nodeType == Node.ELEMENT_NODE) | |
.forEach(e => { | |
return search(e); | |
}); | |
} | |
return; | |
} | |
search(root); | |
console.info(list); | |
document.getElementsByClassName("light"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment