mardi 4 août 2015

Checking Multiple checkboxes using Jquery

In my application I am using a single checkbox to 'Select All' other checkboxes. And below is my code snippet which works for me. But I need a shorter method to reduce my code lines.

$('#CheckAll').change(function(){   
                if ($(this).is(":checked")) {                                       
                    $('.checkboxes').each(function(){                                   
                        $(this).prop("checked", true);                      
                    });
                }
                else{               
                    $('.checkboxes').each(function(){                                   
                        $(this).prop("checked", false);                                                 
                    });             
                }               
            });

Is there any easier way to achieve this using "Ternary Operator".




Aucun commentaire:

Enregistrer un commentaire