DeveloperBreeze

Dark Mode Toggle

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

Related Posts

More content you might like

Tutorial
css

CSS Variables and Custom Properties: Dynamic Theming and Beyond

In this example, the --primary-color is overridden within the .header class, so all elements inside .header will use the new color.

CSS variables are perfect for managing color schemes that can be easily changed or updated across a site.

Sep 05, 2024
Read More
Tutorial
javascript php

Managing Modals with Livewire and JavaScript

  • Basic understanding of Livewire and JavaScript
  • A Laravel project with Livewire installed

We'll create a system to open and close modals using Livewire and JavaScript by dispatching custom events.

Aug 14, 2024
Read More
Code
javascript

Password Toggle

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Detect Dark Mode Preference

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!