xxxxxxxxxx
document.documentElement.style.setProperty("--tab-count", 5);
xxxxxxxxxx
var root = document.querySelector(':root');
root.style.setProperty('--variable', 'lightblue');
/or/
root.style.setProperty('--variable', myColor);
xxxxxxxxxx
document.documentElement.style.setProperty("--main-background-color", "green");
xxxxxxxxxx
document.documentElement.style.cssText = "--tab-count: 3";
/or/
document.documentElement.style.setProperty("--tab-count", 5);
/or/
document.documentElement.setAttribute("style", "--tab-count: 5");
xxxxxxxxxx
document.documentElement.setAttribute("style", "--main-background-color: green");
xxxxxxxxxx
document.documentElement.style.setProperty("--main-background-color", "green");
xxxxxxxxxx
const docStyles = document.documentElement.style;
docStyles.setProperty('--accent', '#ffffff');
docStyles.setProperty('--textColor', '#ffffff');
xxxxxxxxxx
window.getComputedStyle(document.documentElement).getPropertyValue('--var-name');
xxxxxxxxxx
document.documentElement.style.cssText = "--main-background-color: red";
xxxxxxxxxx
const cssVar = ( name, value ) => {
if(name.substr(0, 2) !== "--") {
name = "--" + name;
}
if(value) {
document.documentElement.style.setProperty(name, value)
}
return getComputedStyle(document.documentElement).getPropertyValue(name);
}