mardi 11 août 2015

javascript select/deselect all checkboxes in a form

I want to make a javascript select/deselect all checkbox.

here is my script, but it does not work:

<form id="labels">
<input type="checkbox">
<input type="checkbox" id="select_all">
</form>
<script>
$('#select_all').click(function()
{
        if($("#select_all").is(':checked'))
        {
            $("form#labels input[type='checkbox']").prop('checked', false);
        }else{
            $("form#labels input[type='checkbox']").prop('checked', true);
        }
    });
</script>




Aucun commentaire:

Enregistrer un commentaire