I have a challenge where I want to double the value of an element's property every time it is clicked, using CSS variables. Here's what I have tried:
#circle_1 {
width:50px;
height:50px;
width: var(--size_1, 50px);
height: var(--size_1, 50px);
}
And also this:
// Variables
var circle_1 = document.querySelector("#circle_1");
var size_1 = document.getPropertyValue("--size_1");
// Function to grow the circle
function growCircle() {
var size_1_n = size_1 * 2;
circle_1.style.setProperty("--size_1", size_1_n.value);
}
// Event listener
var el = document.getElementById("circle_1");
el.addEventListener("click", growCircle, false);
You can view the code snippet here https://codepen.io/daiaiai/pen/QQXrGz
However, nothing seems to be happening when I click. I suspect there might be something wrong with `var size_1 = document.getPropertyValue("--size_1");`, but I'm unable to pinpoint the issue. Any guidance would be greatly appreciated!