+ 1
If you name an element in your HTML document using the id attribute, and if the Window object does not already have a property by that name then the id is created by default as property of global object , and  the Window object is given a property whose name is the value of the id . That's the reason why you can use the id without using getElementById
18th Jan 2022, 8:48 AM
Shubham Yadav
Shubham Yadav - avatar
+ 2
18th Jan 2022, 7:47 AM
NEZ - avatar
+ 2
IDs of elements are registered as global variable. Some say this was Chrome specific, so I'm not too sure whether all browsers shows such behaviour. https://dev.to/vuelancer/dom-element-id-as-global-variable-1l2n https://2ality.com/2012/08/ids-are-global.html
18th Jan 2022, 8:48 AM