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

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -