How to use getElementsByClassName() with two classes with JavaScript?

Spread the love

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.

Leave a Reply

Your email address will not be published. Required fields are marked *