css - input :checked & toggle() in jquery -
in jquery have following code, reason not working expected. on testing code doesn't perform css changes. if remove :checked , have $("input") css works on clicking of input:checkbox
$("input :checked").toggle(function() { // stuff every *odd* time element clicked; $(this).siblings('a').css("text-decoration","line-through"); $(this).siblings('a').css("color","#aaa"); $(this).parent('li').css("background-color","#ccc"); }, function() { // stuff every *even* time element clicked; $(this).siblings('a').css("text-decoration","none"); $(this).siblings('a').css("color",""); $(this).parent('li').css("background-color",""); });
what missing?
try this:
$('input:checkbox').click(function() { if($(this).is(':checked')) { // stuff every *odd* time element clicked; $(this).siblings('a').css("text-decoration","line-through"); $(this).siblings('a').css("color","#aaa"); $(this).parent('li').css("background-color","#ccc"); } else { // stuff every *even* time element clicked; $(this).siblings('a').css("text-decoration","none"); $(this).siblings('a').css("color",""); $(this).parent('li').css("background-color",""); } });
here's jsfiddle this: http://jsfiddle.net/awmf3/
Comments
Post a Comment