// 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
Related Posts
More content you might like
CSS Variables and Custom Properties: Dynamic Theming and Beyond
CSS Variables provide an elegant solution for creating flexible, reusable, and dynamic styles. They enable you to build adaptable designs, such as dynamic themes, responsive layouts, and interactive UI components. By incorporating CSS Variables into your workflow, you can create maintainable, scalable styles
heets that are easy to adapt and manage. Keep your variables organized, avoid over-complicating overrides, and leverage the full power of JavaScript to unlock new design possibilities.
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.
Detect Dark Mode Preference
No preview available for this content.
Discussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!