Is this possible if(x.onclick){ x.style.background="red"} | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is this possible if(x.onclick){ x.style.background="red"}

If eventlistener

30th Apr 2019, 7:30 PM
SCP 251
SCP 251 - avatar
2 Answers
+ 11
use x.addEventListener("click", () => ( x.style.backgroundColor = "red" ) )
30th Apr 2019, 7:54 PM
InvBoy [ :: FEDE :: ]
InvBoy [ :: FEDE :: ] - avatar
+ 5
Is "x" a html element? If yes, simply do : x.onclick = () => { x.style.background ="#f00" }
30th Apr 2019, 8:09 PM
Dlite
Dlite - avatar