开发者

Change bg on radio deselect

This is just an add on to my last question. Once I deselect 开发者_如何学JAVAthe radio button I need to return the background color to its original state. So the solution we came up with is:

$(document).ready(function(){
    $('input:radio').change(function(){
        $(this).closest('div').toggleClass('highlight');
    });
});

Now I need to remove the highlight class when the radio button is deselected - any ideas?


Try this, group your radios using the name attribute and the following js should work

Demo

 $('input:radio').change(function(){
        $('div.highlight').removeClass('highlight');
        $(this).closest('div').addClass('highlight');
 });


yes, I agree with redsquare, you can see this my code demo on jsfiddle, with the div onclick select the radio.

$('table div').click(function() {
      $(this).find('input:radio').prop('checked', true);
      $('div.highlight_row').removeClass('highlight');
      $(this).closest('div').addClass('highlight');
});

you can see the full code here, but the change is on tr class, not the div class :

JsFiddle Code Sample

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜