0
Is this possible if(x.onclick){ x.style.background="red"}
If eventlistener
2 Answers
+ 11
use
x.addEventListener("click", () => (
x.style.backgroundColor = "red"
) )
+ 5
Is "x" a html element?
If yes, simply do :
x.onclick = () => {
x.style.background ="#f00"
}