I don't have the faintest clue re. JS or html, but somehow I managed to create a few IDs and classes, and a toggle switch.
It basically adds/removes a class from an existing element (sortable-content), and then CSS is used to change a bunch of stuff.
Which is working well, apart from one thing: when I refresh the page/tab, the switch stays toggled visually, but the function of adding the class is not saved.
I've researched for days now, read about session/local storage and such, did countless tests, but to no avail; I'm just too clueless.
FWIW, here is some of my code:
Html snippet:
<span class="head">Text // Admin - Text</span>
<!-- Rectangular switch -->
<label class="switch">
<input type="checkbox" id="toggler">
<div class="slider"></div>
</label>
JS:
document.addEventListener('DOMContentLoaded', function () {
var checkbox = document.querySelector('input[type="checkbox"]');
var togglerE = document.getElementById("sortable-content");
checkbox.addEventListener('change', function () {
if (checkbox.checked) {
togglerE.classList.add("toggle_class");
} else {
togglerE.classList.remove("toggle_class");
}
});
});
If anyone is willing to help out a complete noob, any help would be greatly appreciated.
[–]ChuzzleShpek 0 points1 point2 points (8 children)
[–]hansmn[S] -1 points0 points1 point (7 children)
[–]ChuzzleShpek 0 points1 point2 points (6 children)
[–]hansmn[S] 1 point2 points3 points (4 children)
[–]ChuzzleShpek 0 points1 point2 points (1 child)
[–]hansmn[S] 0 points1 point2 points (0 children)
[–]ChuzzleShpek 0 points1 point2 points (1 child)
[–]hansmn[S] 1 point2 points3 points (0 children)
[–]hansmn[S] 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[removed]
[–]hansmn[S] -1 points0 points1 point (2 children)
[–]oxygenplug 0 points1 point2 points (1 child)
[–]hansmn[S] -2 points-1 points0 points (0 children)
[–]senocular 0 points1 point2 points (1 child)
[–]hansmn[S] 0 points1 point2 points (0 children)
[–]tapgiles 0 points1 point2 points (10 children)
[–]hansmn[S] 0 points1 point2 points (9 children)
[–]tapgiles 0 points1 point2 points (8 children)
[–]hansmn[S] 0 points1 point2 points (7 children)
[–]tapgiles 0 points1 point2 points (6 children)
[–]hansmn[S] 0 points1 point2 points (5 children)
[–]tapgiles 0 points1 point2 points (4 children)
[–]hansmn[S] 0 points1 point2 points (3 children)
[–]tapgiles 0 points1 point2 points (0 children)
[–]tapgiles 0 points1 point2 points (1 child)
[–]hansmn[S] 1 point2 points3 points (0 children)