netten
netten

Reputation: 27

Jquery checkbox click issue

I have a check box on my form with id="chkBold". When i click or check this checkbox, i want element

to change color. Here is my code and entire page. It does not change color. Can you see what is wrong here?

Thanks.

(function () {
    $("#chkBold").click(function(){
        if($("#chkBold").is(':checked')) {
            $("p").css('color', 'Blue'); 
        }else{
            $("p").css('color', 'Red'); 
        }
     });
});


 jsfiddle: http://jsfiddle.net/netten/dAesw/

Upvotes: 0

Views: 115

Answers (4)

soupy1976
soupy1976

Reputation: 2845

I just tried tidying up your jsfiddle and it seems to work... http://jsfiddle.net/8fggu/2/

Upvotes: 0

Rupesh Patel
Rupesh Patel

Reputation: 3065

Try to debug at

if($("#chkBold").is(':checked'))
               {
                alert($('p'));   
                $("p").css('color', 'Blue'); 
                }

make sure this selector gives you the same element you want to change the color, one more thing , Do you want to change the font color or the backgroundColor, both are different.

Upvotes: 0

swapnesh
swapnesh

Reputation: 26732

Check this working model ---

http://jsfiddle.net/swapnesh/Xwj6n/

Upvotes: 0

adeneo
adeneo

Reputation: 318342

You're missing a dollar sign :

$(function () {
    $("#chkBold").click(function(){
        if($(this).is(':checked')) {
            $("p").css('color', 'blue'); 
        }else{
            $("p").css('color', 'red'); 
        }
     });
});

Upvotes: 3

Related Questions