Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to change a css variable with javascript

var root = document.querySelector(':root');
root.style.setProperty('--variable', 'lightblue');
/or/
root.style.setProperty('--variable', myColor); 
Comment

how to change css variable in javascript

document.documentElement.style.setProperty("--main-background-color", "green");
Comment

set css variable from javascript

document.documentElement.style.cssText = "--tab-count: 3";
/or/
document.documentElement.style.setProperty("--tab-count", 5);
/or/
document.documentElement.setAttribute("style", "--tab-count: 5");
Comment

how to change css variable in javascript

document.documentElement.setAttribute("style", "--main-background-color: green");
Comment

change css variable with javascript

document.documentElement.style.setProperty("--tab-count", 5);
Comment

js set css variable

document.documentElement.style.setProperty("--main-background-color", "green");
Comment

how to set css variables in javascript

		const docStyles = document.documentElement.style;

		docStyles.setProperty('--accent', '#ffffff');
		docStyles.setProperty('--textColor', '#ffffff');
Comment

how to change css variable in javascript

document.documentElement.style.cssText = "--main-background-color: red";
Comment

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

}
Comment

change css variable with javascript

let root = document.documentElement;

root.addEventListener("mousemove", e => {
  root.style.setProperty('--mouse-x', e.clientX + "px");
  root.style.setProperty('--mouse-y', e.clientY + "px");
});
Comment

change css variable with javascript

element.style.setProperty("--my-var", jsVar + 4);
Comment

PREVIOUS NEXT
Code Example
Javascript :: get array from string javascript 
Javascript :: javascript document get by attribute 
Javascript :: mongoose id validator 
Javascript :: age calculator moment js 
Javascript :: javascript autocomplete 
Javascript :: spread operator es6 
Javascript :: Auto increment in realtime database with javascript 
Javascript :: object.assign in node.js 
Javascript :: date range picker jquery 
Javascript :: why does array index start from 0 
Javascript :: js Destructuring in React 
Javascript :: javascrip functions parameters 
Javascript :: angularjs select placeholder 
Javascript :: Find the maximum number of an array js 
Javascript :: lottie npm 
Javascript :: know when recyclerview is on the last item 
Javascript :: Using the Set object 
Javascript :: double click react 
Javascript :: if page is loading then show loader in js 
Javascript :: react native stopwatch 
Javascript :: js if 
Javascript :: javascript linting 
Javascript :: find element and find elements 
Javascript :: convert javascript date into excel date 
Javascript :: convert datetime value to time only in reactjs 
Javascript :: nextjs use dotnenv 
Javascript :: next greater element javascript using stack 
Python :: All caps alphabet as list 
Python :: get random line from file python 
Python :: numpy array remove scientific notation 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =