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

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

set css var with javascript

// this is for site-navigation with more sub ul-blocks.
// in css root{--ul-hover-height:100px} //fallbackvalue 
// in css: nav ul ul:hover{height:--ul-hover-height;}

// to make it dynamic using JS: 
// set variable ul ul height depending on nr. of li's:
function setUlHeight(elem){        
    parentHeight=window.getComputedStyle(elem.parentNode).height
    parentHeight=parseInt(parentHeight)*1.2 //to cover li padding/margin..
    elemHeight=parentHeight * elem.childElementCount
  
    let root = document.documentElement;           
    root.style.setProperty('--ul-hover-height', elemHeight); }
Comment

set css var with javascript

// this is for site-navigation with more sub ul-blocks.
// in css root{--ul-hover-height:100px} //fallbackvalue 
// in css: nav ul ul:hover{height:--ul-hover-height;}

// to make it dynamic using JS: 
// set variable ul ul height depending on nr. of li's:
function setUlHeight(elem){        
    parentHeight=window.getComputedStyle(elem.parentNode).height
    parentHeight=parseInt(parentHeight)*1.2 //to cover li padding/margin..
    elemHeight=parentHeight * elem.childElementCount
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

PREVIOUS NEXT
Code Example
Javascript :: object destructuring javascript 
Javascript :: jquery header basic auth 
Javascript :: js add key to object 
Javascript :: or inside if javascript 
Javascript :: settimeout js for loop 
Javascript :: javascript loop backwards through array 
Javascript :: recursion javascript 
Javascript :: react select with custom option 
Javascript :: submit form using jquery 
Javascript :: javascript trigger event 
Javascript :: instantiate template playcanvas 
Javascript :: get index of element in array js 
Javascript :: on resize javascript 
Javascript :: if else dart 
Javascript :: jquery element width 
Javascript :: javascript write to text file 
Javascript :: flutter intl currency 
Javascript :: dynamodb pagination nodejs 
Javascript :: set cookie in reactjs 
Javascript :: Shortest ajax get method jquery 
Javascript :: wait for element to load javascript 
Javascript :: suppress spaces in front and in the end of a string javascript 
Javascript :: vue js default props 
Javascript :: force click btn using jquery 
Javascript :: javascript select change selected 
Javascript :: javascript object array contains 
Javascript :: javascript count no of lines 
Javascript :: how to enable click copy function using js 
Javascript :: stop window.setinterval javascript 
Javascript :: js filter out doubles 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =