From the course: JavaScript Code Challenges: Creating Web Apps
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Dark and light mode - JavaScript Tutorial
From the course: JavaScript Code Challenges: Creating Web Apps
Dark and light mode
- [Instructor] Right now our app is functioning pretty nicely already, but let's make it even cooler by adding a dark and light mode to it. At this point, we only have a light mode, so let's go ahead and add a checkbox for setting it to dark modes. What I want to happen is that when we check the box, it switches to dark modes, and in order to do that, I actually need to have the CSS for my dark mode in place as well. There we go. I'm having dark mode classes on my body for a few of the elements, but then I need to make sure that the dark mode class gets added. And in order to do that, I need to adjust my script a little bit. All I need is to add an event listener to my theme toggle. So let's go ahead and do it like this. So when we change it, I'm going to toggle the dark mode class and I'm going to set it to whether the theme toggle is checked or not. Alright, let's see this in action. So here's our light mode version, and as you can see, when I tick the box, it turns into dark mode…
Contents
-
-
-
-
-
-
-
(Locked)
Introduction: Web-based code editor55s
-
(Locked)
Planning the features1m 3s
-
(Locked)
Creating the UI2m 28s
-
(Locked)
Overview of the necessary JavaScript concepts1m 12s
-
(Locked)
Text area and live preview2m 31s
-
(Locked)
Adding syntax highlighting4m 21s
-
(Locked)
Dark and light mode1m 46s
-
(Locked)
Final touches1m 25s
-
(Locked)
Challenge: Multiple language support2m 5s
-
(Locked)
Solution: Multiple language support2m 8s
-
(Locked)
-