To use getElementsByClassName() with two classes with JavaScript, we use querySelectorAll
.
For instance, we write
const els = document.querySelectorAll(".a,.b");
to call querySelectorAll
to select all the elements with classes a
and b
and return the elements in a node list.