Class names are how most code labels elements: card, active, is-open. root.getElementsByClassName("card active") finds every element inside root that has all the classes listed, in document order. Writing it yourself means two small but exact jobs: split the argument into names the way the browser does, and walk the tree checking each element's class list.
Write getElementsByClassName(root, classNames) in by-class.js. It returns the same elements, in the same order, as root.getElementsByClassName(classNames), but as an array.
The result is an array of every matching descendant of root, at any depth, in document order, and never root itself.
Class names match whole names only: item does not match items, item-x or my-item.
With several names, an element must have all of them; the order of the names does not matter, and a name given twice counts once.
The names are separated by any run of ASCII whitespace (space, tab, line feed, form feed, carriage return), at the start and end too. A non-breaking space is part of a name, not a separator.
An empty or blank argument matches nothing.
Class names are case-sensitive, and names with characters like :, / or [ work like any other.
SVG elements are searched like HTML elements.
It works when root is the document, a detached element or a fragment, and it never looks inside template content or shadow roots.
The result is a snapshot that later changes to the page do not alter. Nothing matching gives [].
It works on large trees, and with every built-in search method removed.
Plain JavaScript in a browser page; the tests call the global getElementsByClassName from by-class.js.
Not allowed: getElementsByClassName, getElementsByTagName, getElementsByTagNameNS, querySelector and querySelectorAll. Two tests remove them all while they run. children and classList are allowed.
The page is in standards mode (it has a doctype), where class names are case-sensitive.