lundi 21 septembre 2015

Trigger checkbox change class in Jquery

I am new to jQuery. I am trying to make a switcher using a checkbox. At the moment I have gone this far

$(function(){
    $('input.cbx').on('change', function() {
        if($(this).prop("checked", true))
        {
          $('body').addClass('dark');
        } else if($(this).prop("checked", false))
        {
            $('.body').addClass('light');
        }
    });
});
<script src="http://ift.tt/1oMJErh"></script>

<input id="dn" type="checkbox" class="cbx hidden"/>
      <label for="dn" class="lbl"></label>

As you can see the checkbox stay checked after the first click, I imagine is a noob situation but, can you help me please?




Aucun commentaire:

Enregistrer un commentaire