Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get css custom property javascript

/* This will return the value of the --color custom property
   from the root element */
getComputedStyle(document.documentElement).getPropertyValue('--color')

const customButton = document.querySelector('.custom-btn')
/* This will return the value of the --color custom property
   from the root element since it is inherited down to the
   customButton element. */
getComputedStyle(customButton).getPropertyValue('--color')

/* This will return the value of the --background-color
   custom property from this customButton element */
getComputedStyle(customButton).getPropertyValue('--background-color')
Comment

javascript use css custom properties

Values in JavaScript
To use the values of custom properties in JavaScript, it is just like standard properties.
// get variable from inline style
element.style.getPropertyValue("--my-var");

// get variable from wherever
getComputedStyle(element).getPropertyValue("--my-var");

// set variable on inline style
element.style.setProperty("--my-var", jsVar + 4);
Comment

PREVIOUS NEXT
Code Example
Javascript :: ecmascript 7 getmonth as 2 digits 
Javascript :: how to upload file in material ui 
Javascript :: on hover add class on children jquery 
Javascript :: write own nodemon in package.json 
Javascript :: date-and-time npm 
Javascript :: multiple value selected in select2 
Javascript :: include jsp in another jsp 
Javascript :: faker.js name 
Javascript :: javascript get date of the week 
Javascript :: flip a coin javascript 
Javascript :: extract urls from string javascript 
Javascript :: javascript compare arrays remove duplicates 
Javascript :: eject expo app to android and react native 
Javascript :: chamar arquivo javascript no html 
Javascript :: enzye check if it renders 
Javascript :: toggle checkbox in javascript 
Javascript :: how to check if a number is a whole number in javascript 
Javascript :: jquery select a dynamic element 
Javascript :: fs , valid path check 
Javascript :: js convert truthy 
Javascript :: prime numbers 1 to 100 in javascript 
Javascript :: ejs variable 
Javascript :: radio button onclick jquery 
Javascript :: convert data into json format in javascript 
Javascript :: gulp runSequence 
Javascript :: append object to object javascript 
Javascript :: npm http angular 
Javascript :: NameError: uninitialized constant Shoulda 
Javascript :: pagination hook react 
Javascript :: set date to input date js 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =