当复选框被选中和关闭时,如何向复选框的容器div添加类? [英] How do I add a class to the container div of a checkbox when the checkbox is checked on and off?

查看:204
本文介绍了当复选框被选中和关闭时,如何向复选框的容器div添加类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用jquery激活复选框(input.check-group)时,我想向容器(div.checkbox_db)添加一个背景颜色。我可以这样做吗?这是我使用的html代码:

I want to add a background color to the container(div.checkbox_db), when the checkbox(input.check-group) is activated using jquery. Can I do this..? Here is my html code I am working with:

<div class="grid_3 checkbox_db off-check">

    <input type="checkbox" class="check-group" id="check-1" name="check-1">

    <label for="check-1" class="group">Checkbox</label>

</div>


推荐答案

$('.check-group').click(function(){
  if($(this).is(':checked')){
    $(this).parent().addClass('some_class');
  }else{
    $(this).parent().removeClass('some_class');
  }
});

这篇关于当复选框被选中和关闭时,如何向复选框的容器div添加类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆