+ 1

Can someone explain why this code works despite commenting out the getElement line.

I mistakenly forgot to get an element in my code and i used it id with the style method and it worked, it makes me curious. https://code.sololearn.com/WHrldXW435YF/#html

8th Jan 2019, 2:25 PM
Yussuf Toheeb
Yussuf Toheeb - avatar
5 Réponses
+ 4
Because all elements which you assigned an id are accessible also with "window.element_id" or simply "element_id"
8th Jan 2019, 2:45 PM
KrOW
KrOW - avatar
+ 4
Yussuf Toheeb Notice than though window.el_id works on many browser ITS NOT the proper way to handle the problem. Its an old way implemented in IE and used by other browsers also but the "official" way is use getElementById or querySelector functions
8th Jan 2019, 3:05 PM
KrOW
KrOW - avatar
+ 4
👍👍👍
8th Jan 2019, 7:01 PM
KrOW
KrOW - avatar
+ 2
Thanks Is it now safe to use the method, I mean ID straight without getting them to a variable before using them?
8th Jan 2019, 2:58 PM
Yussuf Toheeb
Yussuf Toheeb - avatar
+ 2
Now I got it clearer. Thanks KROW, I appreciate it
8th Jan 2019, 5:52 PM
Yussuf Toheeb
Yussuf Toheeb - avatar