How to get elements with multiple classes

Say I have this:

<div class="class1 class2"></div>

How do I select this div element?

document.getElementsByClassName('class1')[0].getElementsByClassName('class2')[0]

That does not work.

I know that, in jQuery, it is $('.class1.class2'), but I’d like to select it with vanilla JavaScript.

8 Answers
8

Leave a Comment