Style all Inputs but checkbox and radio
Asked Answered
S

4

31

I am trying to use a style where I use

input:not([type=checkbox]),
input:not([type=radio]){ ...

But clearly that won't work. How can I use the styles I have written for all inputs but just these two?

Savoirvivre answered 7/2, 2014 at 2:41 Comment(0)
C
87

You need to use a single combined selector instead of two selectors:

input:not([type=checkbox]):not([type=radio]) { ... }

This selects any input element that does not have the attribute type=checkbox and that does not have the attribute type=radio. The code in the question, with two selectors, selects all input elements that do not have the attribute type=checkbox and additionally all input elements that do not have the attribute type=radio, so it ends up with selecting all input elements.

Usual CSS Caveats apply. You may wish to use polyfill like Selectivzr to cover old versions of IE.

Chrystal answered 7/2, 2014 at 6:31 Comment(1)
I found I needed quotes around the word radio and the word checkbox, otherwise this works great, thanks! input:not([type='radio']):not([type='checkbox'])Donaugh
G
3

If you can use javascript, specifically jquery, than you can use this

$("input:not(:checkbox):not(:radio), select").addClass('myClass');

which will add class myClass to all inputs(and selects) but radio and checkbox

taken from this answer https://mcmap.net/q/470413/-operation-with-all-inputs-without-type-quot-checkbox-quot

Greywacke answered 26/3, 2014 at 8:47 Comment(0)
P
1

You need to style all the other types except these two, awful as it may be.

You could try to add a class to the ones you don't want styled, and then use this in your CSS:

 input:not(.not){ /*Whatever styling you use*/ }
Predominate answered 7/2, 2014 at 2:44 Comment(3)
I can't add to this html unfortunately without JavaScript. I am using Drupal for my CMS, and we've used these inputs in multiple different scenarios at this point.Savoirvivre
Can you use Javascript?Predominate
Unfortunately I can not. I think I will have to add each type of input in this format input[type="TYPE1"], input[type="TYPE2"] I just can't find a good enough list with all the types.Savoirvivre
B
1

If you want to use it inside a Javascript file, you could use this instead:

$("input").not(["type=checkbox"]).not("#id").each(function() {

I'm using it for example in a loop, excluding all the checkboxes and the element with id = id

Bendy answered 18/10, 2018 at 8:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.