Closed renege closed 9 years ago
The following works:
$('.onoffswitch-checkbox').attr('checked', 'checked');
But if you wanna re-toggle all to the "off-state", it doesn't work:
$('.onoffswitch-checkbox').removeAttr('checked');
Thanks for opening an issue! You can retrieve all checked checkboxes using the :checked
selector...
$('.onoffswitch-checkbox:checked').something();
To toggle checked state, it works the same as with any native checkbox. Note that the checked attribute is not the same thing as the checked property. Have a look at "Attributes vs. Properties" on this page.
@timmywil,
Yes ok, but it is not working like that:
$(document).on('click', '#resetStates', function(){
$.ajax({
type: 'POST',
url: '/disable-all',
complete: function() {
$('.onoffswitch-checkbox').removeProp('checked');
}
});
});
$(document).on('click', '#enableAll', function(){
$.ajax({
type: 'POST',
url: '/enable-all',
complete: function() {
$('.onoffswitch-checkbox').prop('checked');
}
});
});
Don't remove the property. Set it to false.
.prop("checked", false)
I have multiple checkboxes with the plugin enabled. I wanna do something like;