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..

1

3 Answers 3

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!

Sign up to request clarification or add additional context in comments.

3 Comments

i added like $('#specific_consultant_no').css('color','red'); but did not work ....
is your id unique on your page - following the standards, it has to be!
does your assignment of the css-attribute be in a click-eventHandler? please support more code, so that i can help you!
8

You could use the css function:

$(function() {
    $('#specific_consultant_no').click(function() {
        $(this).css('color', 'red');
    });
);

Comments

1
$("#myButton").on('click', function () {
        $(this).toggleClass('green');
        $("#result").toggle();
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.