JavaScript Answers

How to Call document.querySelectorAll with Multiple Conditions?

Spread the love

We can use commas to separate different kinds of elements we want to select.

For instance, if we have the following HTML:


Then we can select all the elements by writing:

const list = document.querySelectorAll("form, p, legend");

list would have all the elements in the HTML in the list.

Each item separated by a comma is its own CSS selector.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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