I am in need of assistance to activate my HTML/CSS 'Toggle Switch' using JavaScript.
My goal is to have the text within the DIV hidden by default, and when the slider (switcher) is swiped to the left, it should trigger the DIV to be shown using JavaScript.
I believe I am on the right track, but there seems to be a small issue with my current action...
function toggleDiv() {
var triggeredDiv = document.querySelector('.triggeredDiv');
if (document.getElementById('flipswitch').checked) {
triggeredDiv.classList.remove('shown');
} else {
triggeredDiv.classList.add('shown');
}
}
document.getElementById('flipswitch').addEventListener("change", toggleDiv);
.flipswitch {
position: relative;
width: 200px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
.flipswitch input[type=checkbox] {
display: none;
}
.flipswitch-label {
display: block;
overflow: hidden;
cursor: pointer;
border: 2px solid #999999;
border-radius: 50px;
}
.flipswitch-inner {
width: 200%;
margin-left: -100%;
-webkit-transition: margin 0.3s ease-in 0s;
-moz-transition: margin 0.3s ease-in 0s;
-ms-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s;
transition: margin 0.3s ease-in 0s;
}
All other CSS code goes here
All Other HTML Code Goes Here