1

I want to select all elements that don't have a specific class, how can I do this ? I would like to have something like :

var test = document.getElementsByClassName(!"class");

1 Answers1

1

Use

var test = document.querySelectorAll(":not(.class)");

But you'd better be a little more precise, for example targeting only divs:

var test = document.querySelectorAll("div:not(.class)");
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • 1
    I wanted to select all the in a specific table, and I did it with var test = document.querySelectorAll("#id td:not(.troupe)"), and it works – Ronan LE QUERRÉ May 06 '15 at 08:54