Hey everyone! I’ve got this cool dark mode feature on my website using CSS. It works great with a keyboard shortcut, but now I want to add a button to switch it on and off. Here’s what I’ve got so far:
This works fine when I press Enter, but I’m stuck on how to make it work with a button click. Any ideas on how to modify this code to work with a button instead? Thanks for your help!
I’ve implemented a similar feature using a different approach that might be worth considering. Instead of toggling classes, I used CSS custom properties (variables) to manage the color scheme. Here’s a simplified version:
This approach allows for more granular control over individual colors and can be easier to maintain as your site grows. It also avoids potential issues with the invert filter affecting images or other elements unexpectedly.