javascript - Getting checked checkboxes with jQuery -


i have function supposed catch changes checkboxes. works when boxes clicked manually, not work when toggleall() function triggers them.

anyway correct this?

$(function() {     $(":checkbox").change(function(){     if ( this.checked ) {         alert(this.id+' checked');     } else {         alert(this.id+' not checked');     }     }); });  function toggleall() {     var selectallcheckbox = $("#selectallcheckbox");     if ( selectallcheckbox.prop('checked') ) {         // uncheck them         $("[id^=friendrequestcheckbox]").attr('checked', false);     } else {         // check them         $("[id^=friendrequestcheckbox]").attr('checked', true);     } } 

i running old version of jquery , have not updated new version including prop, in case that's relevant.

when changing elements programmatically, have trigger event programmatically. try :

$("[id^=friendrequestcheckbox]").trigger('change') 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -