// 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
Continue Reading
Discover more amazing content handpicked just for you
Tutorial
css
CSS Variables and Custom Properties: Dynamic Theming and Beyond
With CSS variables, you can dynamically adjust font sizes and easily apply these changes across various elements.
:root {
--font-size-base: 16px;
--font-size-large: calc(var(--font-size-base) * 1.5);
}
h1 {
font-size: var(--font-size-large);
}
Sep 05, 2024
Tutorial
javascript php
Managing Modals with Livewire and JavaScript
Add methods to dispatch custom browser events when buttons are clicked:
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class ModalManager extends Component
{
public function openUserProfileModal()
{
$this->dispatchBrowserEvent('open-modal', ['modalId' => 'user-profile-modal']);
}
public function openSettingsModal()
{
$this->dispatchBrowserEvent('open-modal', ['modalId' => 'settings-modal']);
}
public function openNotificationsModal()
{
$this->dispatchBrowserEvent('open-modal', ['modalId' => 'notifications-modal']);
}
public function render()
{
return view('livewire.modal-manager');
}
}
Aug 14, 2024
Code
javascript
Detect Dark Mode Preference
No preview available for this content.
Jan 26, 2024
Discussion 0
Please sign in to join the discussion.
No comments yet. Start the discussion!