1

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:

Community
  • 1
  • 1
Marcel
  • 15,039
  • 20
  • 92
  • 150
  • 1
    Can't you simply apply changes to other classes and leave the default `.input` selector suited for the input that has no class ? – Brewal Jan 15 '15 at 14:15
  • @Brewal Unfortunately not, as I am creating a "super-css" that gets applied on top of an existing page. My CSS should be suitable for use with the "stylish"-plugin for Firefox. – Marcel Jan 15 '15 at 14:35
  • I voted for reopening, as the linked answers do not actually answer this question. Although they are not wrong, they only provide a workaround, not an answer. – Marcel Jan 15 '15 at 14:40
  • 1
    As the one who answered the second duplicate question I can confirm that it's completely different. – BoltClock Jan 15 '15 at 16:40

2 Answers2

10

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">
Weafs.py
  • 22,731
  • 9
  • 56
  • 78
2

You can use a selector like this:

input:not([class]) {
    /* style for inputs without classes */
}


JSFIDDLE DEMO

reference

Community
  • 1
  • 1
JRulle
  • 7,448
  • 6
  • 39
  • 61
  • Thanks, especially for the JSFiddle demo. Nice! – Marcel Jan 15 '15 at 14:47
  • 1
    Glad to help. If the classes on your site are dynamic (added/removed from elements via javascript), you may want to also consider catching for this alternative `input[class=""] { ... }` which would catch elements with blank classes -- [**updated JSfiddle**](http://jsfiddle.net/fd5dq03a/1/) – JRulle Jan 15 '15 at 14:50