+ 1

How do I do this?

So I am trying to make a button that toggles through light and dark mode but idk how to make it change multiple elements because now it only changes the body const toggleButton = document.getElementById('toggleButton') toggleButton.addEventListener('click', () => { document.body.classList.toggle('darkmode'); }); I have tried to change the "document.body" to another element like "document.fieldset" but it doesn't really work https://sololearn.com/compiler-playground/WQXaftOyL5b6/?ref=app

28th Dec 2024, 12:10 PM
Pro Gamer 12 Nobody
Pro Gamer 12 Nobody - avatar
2 Respostas
+ 5
1. Issue: Your html code is not inside the <body> and the <html> tags – the html part is invalid. 2. Issue: Semantically inaccurate use of <fieldset>: Fieldset groups section with forms, and should not be used for arbitrary grouping. https://developer.mozilla.org/de/docs/Web/HTML/Element/fieldset 3. Dark mode: I'd suggest to only apply the darkmode class to the body as you do now. Add specifications relative to body.darkmode. Example: body.darkmode fieldset { ... } https://sololearn.com/compiler-playground/WF11c7i4q3U7/?ref=app
28th Dec 2024, 12:33 PM
Lisa
Lisa - avatar
0
Thanks
28th Dec 2024, 1:27 PM
Pro Gamer 12 Nobody
Pro Gamer 12 Nobody - avatar