I'm trying my best to theme a website with CSS root variables and jQuery / Javascript.
:root {
--color1: red;
--color2: green;
--background-color: var(--color1);
--text-color: var(--color2);
}
When a button is clicked, I want to "toggle" both the background and text color css variables. The following example works well (just once, no toggle) - it just adds the given style properties to my html tag.
document.documentElement.style.setProperty('--background-color','var(--color2)');
document.documentElement.style.setProperty('--text-color','var(--color1)');
=> <html style="--text-color=var(--color1);--background-color=var(--color2);"
How could I make this to toggle to other "themes" when clicking the button after the initial click?