0

Can’t update a div’s style

I’m currently trying to change the div’s background color whenever I press a button (which runs a function which in turn updates the window in question), but it refuses to update, saying the variable isn’t an object. I also can’t update the window to anything else, suggesting I made a baseline error. I’d greatly appreciate help or suggestions. https://code.sololearn.com/W1dspZEP80Pt/?ref=app

10th Jul 2020, 12:45 PM
Pxnt
Pxnt - avatar
3 ответов
+ 6
Hey Pxnt, You have well written code, the only mistake you are making is using wrong object for doing DOM manipulation. You have to use document object not the window object. Window object contains methods like alert() and prompt() which does not have anything to do with DOM. document object is responsible for doing all manipulation. [FIXED] https://code.sololearn.com/Wx12lW8QzzFj/?ref=app
10th Jul 2020, 12:49 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 6
Pxnt Oh well haha I did not see that you are actually defining the window variable. I executed the code and got line number where error is occurring and saw that you're trying to do stuff with window object. Happy Coding :D
10th Jul 2020, 12:56 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 1
🔫 Rick Grimes thank you for your help! while you didnt point out exactly what I was looking for, i can now see my mistake - the variable window is already taken. Thank you!
10th Jul 2020, 12:51 PM
Pxnt
Pxnt - avatar