Skip to content
Advertisement

How to add multiply styles document.documentElement.style.setProperty (js)

I’m adding dark and light theme, I changed bg-color, but can’t change text color

Css (I don’t have variables)

JavaScript

Js

JavaScript

Advertisement

Answer

If I were you I’d have added a class to the body element such as “.darkTheme” and that’d be only one line of JS and a faster program. The snippet below shows you how to do it, just a point that you can have the body inherit a theme (class) by default.

JavaScript
JavaScript
JavaScript

Although if you don’t seek this way, I can help you with your own.

The point is your JS code ends the setProperty method with “);” and you can’t expect your code to work as “(‘–text-color’, ‘white’)” makes no sense.

You can edit your JS like this:

JavaScript
Advertisement