How to exclude specific class names in querySelectorAll()?

Tags:



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?

Answer

Use :not CSS pseudo-class:

document.querySelectorAll('span.test:not(.asd)');


Source: stackoverflow