Why does this (event handler) doesn't work? [Solved ✅] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why does this (event handler) doesn't work? [Solved ✅]

Why does this (the event handler) doesn't work? According to w3school, they said, "In HTML event handlers, this refers to the HTML element that received the event," but when I used them, they don't work. In Khan Academy, it worked, but in solo-learn, it didn't. Here's the code if you want the whole thing: https://code.sololearn.com/Wr73mxlcVY7D/#html

23rd Sep 2020, 2:28 AM
:DD
:DD - avatar
5 Answers
+ 2
Thank you! .■. for answering, but I found my answer on the comments on the project. Ipang commented, "'this' in function refers to 'window' object, use 'event.target' in place of 'this' Thank you Ipang for the answer! Problem Solved! ✅
23rd Sep 2020, 3:23 AM
:DD
:DD - avatar
+ 5
Check your css part .eyes { background-color: black; } You can change background color of eye
23rd Sep 2020, 2:38 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 4
Try this is js part function why() { document.body.style.backgroundColor= "red"; }
23rd Sep 2020, 2:33 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Well... I wanted to use the js this keyword and I wanted to change the backgroundColor of the circle but still... Thank You :D
23rd Sep 2020, 2:37 AM
:DD
:DD - avatar
0
Thank you :D But I wanted to change the color using javascript and I wanted to use this keyword to change it... but this keyword doesn't work :'(
23rd Sep 2020, 2:45 AM
:DD
:DD - avatar