vendredi 3 novembre 2017

Jquery check all checkboxes doesn't work inside if statement

The following line on page load successfully checks all checkboxes:

$(':checkbox').prop("checked",true);

But when running it inside a click event of a button it doesn't, the html value and alert successfully work though so the if statement does work.

$('#selectAll').click(function(){
                 if($(this).html() == 'Check All'){
                     $(':checkbox').prop("checked",true);
                     $(this).html('Uncheck All');
                     alert('check all');
                 }
                 else{
                     $(':checkbox').prop("checked",false);
                     $(this).html('Check All');
                     alert('uncheck all');
                 }
            });




Aucun commentaire:

Enregistrer un commentaire