#id is in window
TL;DR DOM node IDs are directly available in the window
object.
<div id='foo'></div>
console.log(window.foo) // HTMLElement
Though, you shouldn’t access the DOM that way.
Unless it conflicts with other attributes of the window
object, all DOM nodes with a specified id
are directly accessible as properties of the window
object.
<div id='foo'></div>
<div id='Date'></div>
console.log(window.foo) // HTMLElement
console.log(foo) // HTMLElement
console.log(window.Date) // ƒ Date()
Careful: it isn’t recommended to access the DOM this way as it will easily lead to hard to find errors and could conflict with native APIs. You should try and use getElementById()
instead. But still, knowing this is useful for rapid prototyping and dirty code.
console.log(document.getElementById('Date')) // HTMLElement