Published on January 26, 2024By DeveloperBreeze

// 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');
});

Comments

Please log in to leave a comment.

Continue Reading:

Detect Dark Mode Preference

Published on January 26, 2024

javascript

Password Toggle

Published on January 26, 2024

javascript

Managing Modals with Livewire and JavaScript

Published on August 14, 2024

javascriptphp