re: DOM elements with ID's are global variables VIEW POST


This is specified the WHATWG spec,

Note that they explicitly point out that this is a bad idea to use in your code:

As a general rule, relying on this will lead to brittle code. Which IDs end up mapping to this API can vary over time, as new features are added to the Web platform, for example. Instead of this, use document.getElementById() or document.querySelector().

code of conduct - report abuse