My code works fine I just need to switch between two colors white and black colors.
document.getElementById("switch").addEventListener("click", function() {
document.getElementsByClassName("mainWrapper fullWidth")[0].style.backgroundColor = document.getElementById("switch").toggle ? "white" : "black";
});
h1 {
color: green;
}
/* toggle in label designing */
.toggle {
float: none;
position: fixed;
display: inline-block;
width: 80px;
height: 38px;
background-color: grey;
border-radius: 30px;
border: 2px solid white;
top: 6px;
/* left: 896px; */
}
/* After slide changes */
.toggle:after {
content: " ";
position: absolute;
width: 38px;
height: 35px;
border-radius: 50%;
background-color: white;
top: -1px;
left: 0px;
transition: all 0.5s;
}
/* Toggle text */
p {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
}
/* Checkbox cheked effect */
.checkbox:checked+.toggle::after {
left: 38px;
}
/* Checkbox cheked toggle label bg color */
.checkbox:checked+.toggle {
background-color: #5ad94d;
}
/* Checkbox vanished */
.checkbox {
display: none;
}
<input class='checkbox' id='switch' type='checkbox' />
<label class='toggle' for='switch'><p>ON OFF</p></label>