Tuesday, 10 September 2013

Why do dom-elements exist as properties on the window-object?

Why do dom-elements exist as properties on the window-object?

If I write html like this:
<div id="foo">Foo<div>
window.foo returns a dom-element and window.document.getElementById("foo")
=== window.foo returns true.
Why is that? And why does everyone use getElementById?
And on a sidenote: Why was overriding window.foo forbidden in IE7/8? And
what happens if I set window.foo = "bar"?

No comments:

Post a Comment