Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change a <label>’s color when its input is disabled?

Tags:

jquery

css

I have some labels like:

  <label>
     <input type="checkbox" name="the_name" id="the_name" /> Label text
  </label>

that sometimes are disabled

$("#the_name").prop('disabled', true);

No problem, but I would like to change label text color to make it more visible. Is it possible using Jquery and/or CSS?

like image 321
Ivan Avatar asked Sep 07 '11 07:09

Ivan


People also ask

What is the color of disabled input?

The DOM Input Color disabled Property in HTML DOM is used to set or return whether a color picker should be disabled or not. A Disabled element is usually is unusable and un-clickable and are usually grey in color by default in all the Browser.

How do you apply style to only those input tags which have disabled attributes to them?

You should use javascript or your templating engine to add and remove a "disabled" class to the label elements. It shouldn't be any difficult since having disabled elements already imply you are using some sort of programming with the forms.

How do you color a label in HTML?

To set the font color in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property color. HTML5 do not support the <font> tag, so the CSS style is used to add font color.


1 Answers

This can be done in CSS, but only when the label comes after the input tag. For example:

HTML:

<input id="someinput" type="text" /><label for="someinput">Type text:</label> 

CSS:

input[disabled] + label { *whatever style you want when input is disabled* } ;
like image 150
Dag Sondre Hansen Avatar answered Sep 22 '22 07:09

Dag Sondre Hansen