Skip to content
Advertisement

How to exclude specific class names in querySelectorAll()?

How can I exclude tag elements that have a specific class name?

<span class="test" />
<span class="test asd" />

document.querySelectorAll('span.test'); //how to exclude all spans with "asd" as class name?

Advertisement

Answer

Use :not CSS pseudo-class:

document.querySelectorAll('span.test:not(.asd)');
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement