var element = document.getElementById("element"); element.style.setProperty("--variable", "new-value");
This code line is setting a new value for a CSS variable. The first line gets the element with the ID of “element”. The second line sets the value of the CSS variable “–variable” to “new-value”.
CSS variables are a great way to store data in your CSS files without having to use global variables. You can use them to store information like the current page’s width or height, or the current font size.
var width = document.getElementById(“myElement”).offsetWidth;
You can also use the css property to access individual values from a variable:
var width = document.getElementById(“myElement”).offsetWidth; var height = document.getElementById(“myElement”).offsetHeight;
Another way to control CSS is to use the style property. This property allows you to set the style for all elements in your document.