Skip to content

Instantly share code, notes, and snippets.

@iankit3
Last active March 8, 2020 17:00
Show Gist options
  • Save iankit3/7a6bd9dae60a419469dc443e401f0dca to your computer and use it in GitHub Desktop.
Save iankit3/7a6bd9dae60a419469dc443e401f0dca to your computer and use it in GitHub Desktop.
document.getElementsByClassName
// 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