js get element from window['id'] vs document.getElementById('id')

Viewed 2663

What is better and what is the difference (performance, browser support...)?

I thought that DOM elements that have an id automatically create in a window object so you don't need to find them in DOM through getElementById. Am I right and what problems it could bring? I can't find any documentation on such a possibility of js window object.

Examples with window:

window['elementId'];
window.elementId;

The same result as getElementById and querySelector

0 Answers
Related