1

I have a radio button like this

<input type='radio' name='specific_consultant' id='specific_consultant_no' 
                                                                      value='no'>No</input>

on .on click of this radio button , I need to change text color like No .. how do i do it..

Giordano
  • 5,422
  • 3
  • 33
  • 49
Hacker
  • 7,798
  • 19
  • 84
  • 154
  • Possible duplicate of [How can I change the text color with jQuery?](https://stackoverflow.com/questions/2001366/how-can-i-change-the-text-color-with-jquery) – Martin Thoma Jul 27 '17 at 07:26

3 Answers3

8

You could use the css function:

$(function() {
    $('#specific_consultant_no').click(function() {
        $(this).css('color', 'red');
    });
);
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
8
$(document).ready(function() {
    var button = $('#specific_consultant_no');
    button.click(function() {
        button.css('color', 'FOO');
    });
});

if you want to reuse the method, you can do eg.

var colorMethod = function() {
    $(this).css('color', 'FOO');
};
$(document).ready(function() {
    var button = $('#specific_consultant_no');
    button.click(colorMethod);
});

you can also use the addClass and removeClass methods, to be more flexible!

  • i added like $('#specific_consultant_no').css('color','red'); but did not work .... – Hacker May 31 '10 at 07:02
  • is your id unique on your page - following the standards, it has to be! –  May 31 '10 at 07:36
  • does your assignment of the css-attribute be in a click-eventHandler? please support more code, so that i can help you! –  May 31 '10 at 08:52
1
$("#myButton").on('click', function () {
        $(this).toggleClass('green');
        $("#result").toggle();
});