Get CSS property value with JS
Posted on March 31, 2020
Get CSS property value with JS
Just a little reminder to myself about reading the value of a CSS property (variable) using javascript:
getComputedStyle(element).getPropertyValue('--myprop')
Of course, if the value is numeric, it's going to have its unit attached, such as '10px'
Just strip it to have the pure number:
getComputedStyle(element).getPropertyValue('--myprop').replace('px', '')