Mark / Uncheck all checkboxes except disabled

2

In this script below it marks and unchecks all checkbox but would like that when a checkbox is "checked" and "disabled" does not change anything. The problem is that I do not know how to do this, would anyone have an idea?

<input type="checkbox"                  class='marcar'  />
<input type="checkbox" checked disabled class='marcar'  />

JS:

<button class='btn btn-large' type='button' title='Todos' id='todos' onclick='marcardesmarcar();'>
       <i class='icon-large  icon-ok'>Click</i>
</button>

<script>
function marcardesmarcar() {
    $('.marcar').each(function () {
        if (this.checked) 
           $(this).attr("checked", false);
        else 
           $(this).prop("checked", true);
    });
}
</script>
    
asked by anonymous 23.03.2016 / 19:56

1 answer

2

You can use $(this).prop('disabled') to check the status of this property. And join in your if like this:

    if (this.checked) {
        if ($(this).prop('disabled')) return;
        else this.checked = false;;
    }

jsFiddle: link

    
23.03.2016 / 20:01