I have designed a toggle button using Pug, and I am running function1 whenever it is clicked. But what I want to do is that when the page is loaded I am getting a value from the backend that I want to use to set the initial state of the toggle button. Is there a way to use DOM manipulation to change the toggle button below? or some other way to do it from client-side Javascript?
p Hours Button
label.switch#toggleButton
input(type='checkbox' onchange='function1(this)')
span.slider.round
I am thinking maybe something like document.getElementById("toggleButton").attr(checked)
or something like that. Any help would be really appreciated.
CodePudding user response:
Pass a value of true
or false
in the property state
, eg { state: true }
if using Express.
p Hours Button
label.switch#toggleButton
input(type="checkbox" onchange="function1(this)" checked=state)
span.slider.round