Possible Duplicate:
IE/Chrome: are DOM tree elements global variables here?
If I have a HTML page containing
<div id='myDiv'></div>
I would usually access this element like so
var myDiv = document.getElementById('myDiv');
myDiv.innerHTML = '';
However in Chrome (v20) I can also access it using
myDiv.innerHTML = '';
or
window['myDiv'].innerHTML = '';
I've tested in Firefox(v13) and IE(v9) and neither support this.
Why does Chrome support this and when was this added? Are there any implications? (I'm assuming that if any variables are declared with the same name then the name will just point at the latest declaration).
I stumbled on this because I was unintentionally using window['id'] to access an element and it all worked until I tried another browser.