If I know the name of a CSS variable eg --thing
I can get it’s value with JavaScript:
const elem = document.querySelector("html");
if (!elem) return;
const style = getComputedStyle(elem);
const myVariable = style.getPropertyValue("--thing");
console.log({ myVariable });
I’ve tried iterating over the properties and looking for names that start with --
however it doesn’t work.
for (let i = 0; i < style.length; i++) {
const propertyName = style[i];
if (propertyName.startsWith("--")) {
console.log(propertyName);
}
}