Search code examples
htmlcsscss-selectorspseudo-class

How to select elements that have no classes?


I need to select all <input type="submit"> elements, that have no class specifier.

With:

<input class="Submit" type="submit" value="Save" name="action_1">
<input class="Button" type="submit" value="Save as" name="action_2">
<input                type="submit" value="Save and Continue" name="action_3">
<input class="Cancel" type="submit" value="Cancel" name="action_4">

It should select the 3rd one only.

I can imagine this CSS:

input[type="submit"]:not(ANY CLASS){
}

But, what should I write as "ANY CLASS"? Or is there a different approach alltogehter? I could enumerate all known classes there, but this is tedious and might change over time.

Note:


Solution

  • You could use :not([class]), which means select an input element that does not have a class attribute.

    input[type="submit"]:not([class]){
      color: red;
    }
    <input class="Submit" type="submit" value="Save" name="action_1">
    <input class="Button" type="submit" value="Save as" name="action_2">
    <input                type="submit" value="Save and Continue" name="action_3">
    <input class="Cancel" type="submit" value="Cancel" name="action_4">