N
N
newaitix2015-11-09 18:57:55
JavaScript
newaitix, 2015-11-09 18:57:55

Why is the dom element available in a variable by id?

If I have a block
<div id="name"></div>
I can refer to it like this

name
или
window.name

That is, the block with the "name" identifier will be available in the name variable, with the body identifier in the body variable, and so on. Any element can be accessed by its identifier through a variable with the name corresponding to the identifier.
And that's the case with any site.
Why?
For me, this is nonsense.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-11-09
@newaitix

stackoverflow.com/questions/3434278/do-dom-tree-el...
not really. Let's say if you explicitly specify a property in window, then it will override this behavior.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question