// Get the dark mode toggle button by its ID
const darkModeToggle = document.getElementById('darkModeToggle');
// Add a click event listener to toggle dark mode on the body
darkModeToggle.addEventListener('click', () => {
// Toggle the 'dark-mode' class on the body
document.body.classList.toggle('dark-mode');
});Dark Mode Toggle
javascript
Related Posts
More content you might like
Tutorial
css
CSS Variables and Custom Properties: Dynamic Theming and Beyond
This approach adjusts the font size based on screen size, allowing for a more responsive experience.
CSS variables can be manipulated in real-time using JavaScript, which opens up possibilities for dynamic UI elements.
Sep 05, 2024
Read More Tutorial
javascript php
Managing Modals with Livewire and JavaScript
We'll create a system to open and close modals using Livewire and JavaScript by dispatching custom events.
Create a Livewire component, or use an existing one where you want to manage modals.
Aug 14, 2024
Read More Code
javascript
Detect Dark Mode Preference
No preview available for this content.
Jan 26, 2024
Read MoreDiscussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!