Categories
JavaScript Answers

How to select element that does not have a specific class with JavaScript?

Spread the love

To select element that does not have a specific class with JavaScript, we use the :not pseudoclass.

For instance, we write

const el = document.querySelector("li:not(.completed):not(.selected)");

to select the first li element that doesn’t have the completed class or selected class with the querySelector method with :not

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 *