I have designed a toggle-switch with CSS and HTML but I want to be able to toggle/change the toggle switch with javascript.
How do I go about this, you can check out the code in this jsfiddle link
<div id="activate" class="toggle-switch" data-ts-color="green">
<label for="ts4" class="ts-label">Activate Account</label>
<input id="ts4" type="checkbox" hidden="hidden">
<label for="ts4" class="ts-helper"></label>
</div>
My Javascript: but it does not work
if (false) {
// turn toggle switch off
$("#ts4").attr("checked", false);
$('#activate').click();
} else {
// turn toggle switch off
$('#ts4').attr("checked", true);
$('#activate').click();
}
I want to be able to toggle the toggle switch programmatically when? I get a value from the database
}were wrong in that, and you just edited, then there is no error left.