I'm attempting to dynamically change the size and color of a circle based on user input in the form fields. However, I've encountered the following error:
Cannot set properties of undefined (setting 'css')
Could anyone provide guidance on how I can resolve this issue?
window.addEventListener("DOMContentLoaded", (event) => {
const inputsize = document.getElementById("size");
const inputcolor = document.getElementById("color");
const circle = document.getElementsByClassName("circle");
let size = 100;
let color = "#b66465";
window.onchange = (event) => {
let myStyles = "height: " + size + "px; width: " + size + "px; background-color: " + color + ";";
circle.style.css = myStyles;
};
inputcolor.onchange = (event) => {
color = inputcolor.value;
let myStyles = "height: " + size + "px; width: " + size + "px; background-color: " + color + ";";
circle.style.css = myStyles;
};
inputsize.onkeyup = (event) => {
size = inputsize.value;
let myStyles = "height: " + size + "px; width: " + size + "px; background-color: " + color + ";";
circle.style.css = myStyles;
};
});