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

Spread the love

Sometimes, we want to select an element that does not have specific class with JavaScript.

In this article, we’ll look at how to select an element that does not have specific class with JavaScript.

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

To select an element that does not have specific class with JavaScript, we use the querySelector method.

For instance, we write

const el = document.querySelector("li:not([class])");

to call querySelector to select all li elements that don’t have the class class in document.

Conclusion

To select an element that does not have specific class with JavaScript, we use the querySelector method.

Leave a Reply

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