I’m creating a to-do list app for my portfolio and I’d like to add a dark-mode feature for my body/background. however, my toggle button looks fine but the switch doesn’t seem to function and I can’t seem to figure out why anyone sees anything wrong or that may be interfering?
function dark() { // setting up dark-mode
var element = document.body;
element.classList.toggle("dark-mode"); //dark-mode class
}
label {
margin: 10px;
cursor: pointer;
width: 50px;
height: 30px;
display: block;
border-radius: 50px;
position: relative;
color: white;
}
.switch {
position: relative;
display: inline-block;
width: 110px;
height: 10px;
margin: 0 10px;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: aqua;
transition: .4s;
border-radius: 35px;
;
}
.switch input {
display: none
}
.slider::before {
position: absolute;
content: "";
height: 20px;
width: 20px;
left: 5px;
bottom: 5px;
background-color: white;
transition: 0.4s;
border-radius: 50px;
}
input:checked+.slider {
background-color: blue;
}
input:checked+.slider::before {
transform: translateX(0px);
}
input:checked+.slider::after {
transform: translateX(8px);
}
<div class="toggle">
<label for="switch">
<input type="checkbox" onclick="dark()" checked>
<span class="slider"></span>
</label>
</div>