Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

css variable value changing with javascript

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);

}
Source by davidwalsh.name #
 
PREVIOUS NEXT
Tagged: #css #variable #changing #javascript
ADD COMMENT
Topic
Name
3+9 =