How to get the switch toggle state(true/false) in javascript
var switchStatus = false;
$("#togBtn").on('change', function() {
if ($(this).is(':checked')) {
switchStatus = $(this).is(':checked');
alert(switchStatus);// To verify
}
else {
switchStatus = $(this).is(':checked');
alert(switchStatus);// To verify
}
});
Here’s How to add the text “ON” and “OFF” to toggle button
$("#togBtn").on('change', function() {
if ($(this).is(':checked')) {
$(this).attr('value', 'on');
alert($(this).val());
}
else {
$(this).attr('value', 'off');
alert($(this).val());
}
});