Archived topic
Dark mode button with javascript
5 replies · Started by elektrum on February 22, 2021
I am following along this tutorial and got it working, however it only modifies the body and not the containers.
I've added this to Hooks but not sure what the containerElement variable should equal to target the background and font colors of .site-content .inside-article and header:
<script>function myFunction() {
var bodyElement = document.body;
var containerElement = ?
bodyElement.classList.toggle("dark-mode");
containerElement.classList.toggle("dark-mode");
}</script>
I am also open to a more elegant method of dark mode if you have suggestions.
Hi there,
Can you link us to the site in question?
To see what you already have to get and idea of what best to suggest.
You can use the private information text field to provide the link. Thank you. :)
Hi Elvin,
I've provided the site in question in Private Info
Try adding these elements to the script's target for dark mode.
header.site-header
.separate-containers .inside-article,
.separate-containers .comments-area,
.separate-containers .page-header,
.one-container .container,
.separate-containers .paging-navigation,
.inside-page-header
Thanks. I switched to WP Night Mode plugin and called the elements you listed. Works great now!
Nice one. No problem. Glad you got it sorted. :D