Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 8, 2020 02:13 pm GMT

How to Get All Custom Properties on a Page in JavaScript

We can use JavaScript to get the value of a CSS custom property. Robin wrote up a detailed explanation about this in Get a CSS Custom Property Value with JavaScript. To review, lets say weve declared a single custom property on the HTML element:

html { --color-accent: #00eb9b;}

In JavaScript, we can access the value with getComputedStyle and getPropertyValue:

const colorAccent = getComputedStyle(document.documentElement) .getPropertyValue('--color-accent'); // #00eb9b

Perfect. Now we have access to our accent color in JavaScript. … Read article “How to Get All Custom Properties on a Page in JavaScript”

The post How to Get All Custom Properties on a Page in JavaScript appeared first on CSS-Tricks.


Original Link: https://css-tricks.com/how-to-get-all-custom-properties-on-a-page-in-javascript/

Share this article:    Share on Facebook
View Full Article

CSS Tricks

A Web Design Community curated by Chris Coyier

More About this Source Visit CSS Tricks