

Are DOM tree elements global variables? - bruth
http://stackoverflow.com/questions/3434278/ie-chrome-are-dom-tree-elements-global-variables-here/3434388

======
khuey
Gecko (Firefox) does this in quirks mode only. We're holding the line against
this for the moment (<http://www.w3.org/Bugs/Public/show_bug.cgi?id=11960>).

------
pak
tldr version, minus the usual stackoverflow backandforth:

Named elements are made into properties of the "window" object in Chrome, IE,
and Opera. That would include any element with an "id" attribute and most
elements with a "name" attribute. Thankfully, any vars you declare in this
scope override the DOM ones.

With some quick testing in Chrome, IE, and Opera, it appears that these
elements are enumerable off of "window" in Opera but _not_ Chrome and IE
(perhaps those two browsers create them only when you access them).

------
mrspeaker
Yep, Microsoft did it, and everyone else (for some reason) followed. My
approach is to actively avoid relying on it for real work - but pull it out
for the JS1K/10K comps ;)

~~~
ootachi
Then you'd be breaking the rules of JS1K, because JS1K demos have to work in
Firefox, and Firefox doesn't support this feature (except in quirks mode,
which you can't turn on in JS1K).

------
ch0wn
You can, however, abuse this quite nicely for size-optimized javascript demos.
For example if you look at some of the <http://js1k.com/> submissions. For
anything other than those experiments, you should of course avoid.

------
crizCraig
The IE guys are saying this needs to be kept for backwards compatibility.
<http://www.w3.org/Bugs/Public/show_bug.cgi?id=11960#c8>

Why can't it be kept for old doctypes and quirksmode like Gecko does? The
HTML5 doctype should get rid of this. Surely _that_ wouldn't break top sites
as MSFT is saying: <http://www.w3.org/Bugs/Public/show_bug.cgi?id=11960#c12>

------
snorkel
Yes.

