Implement getElementsByClassName(root, classNames) without using the built-in getElementsByClassName, querySelector or querySelectorAll.
It returns an array of every element below root (not root itself) that has all of the classes in classNames, in document order (a depth-first, pre-order walk).
document.body.innerHTML = `
<div id="root">
<p class="note warn">A</p>
<section class="warn">
<p class="warn note big">B</p>
</section>
<p class="note">C</p>
</div>`;
const root = document.getElementById('root');
getElementsByClassName(root, 'note warn').map((el) => el.textContent); // ['A', 'B']
getElementsByClassName(root, 'warn').length; // 3
getElementsByClassName(root, ' '); // []
classNames is a string of class names separated by any whitespace (spaces, tabs, newlines). Extra whitespace is ignored and order doesn't matter."warn" must not match class="warning".classNames matches nothing.HTMLCollection. What does that mean, and what bugs can it cause?TreeWalker instead?Spotted a mistake or a rights concern? Report an issue