V
V
Vladislav Chernushevich2015-10-21 03:20:11
JavaScript
Vladislav Chernushevich, 2015-10-21 03:20:11

Why is the console outputting html?

There is such a code .
<div id="box"></div>
If you write
console.log(box)
Then, the following html code will be displayed in the console <div id="box"></div>
. Why is this happening? The variable was not declared anywhere. What kind of feature is this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Yarosh, 2015-10-21
@voidnugget

All elements of the DOM tree with a declared id automatically become attributes of the global window object. console.log(box);and console.log(window.box);- one and the same. This is standard behavior for modern browsers (ES5+ afaik) and one of the reasons id based sectors are slower than class attribute based unique selectors, hi bem.
On the example of the same page, you can drive it console.log(window.adriver_banner_403766071);into the browser console.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question