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
Post a Comment