I created an <input type = "color"> inside a custom element because it is not present in the wix editor. I would like to change the background of a div (within another custom element) but I can't run onchange.
the code I made is the following:
let createInputColor = () =>{ let inputColor = document.createElement("input"); inputColor.setAttribute("type", "color"); inputColor.setAttribute("id", "input-color"); inputColor.setAttribute("onchange", "cPicker()"); return inputColor; }; let createInputContainer = () => { let inputContainer = document.createElement('div'); inputContainer.id = 'input-container'; inputContainer.appendChild(createInputColor()); return inputContainer; }; let cPicker = () => { let color = document.getElementById("input-color").value; document.getElementById("input-container").style.backgroundColor = color; }
this only sets the initial color value and doesn't work when another color is chosen.