logoalt Hacker News

chmod775yesterday at 7:15 PM1 replyview on HN

More specifically it becomes a property of window, which is the global object.

So <div id="hello"> becomes accessible as window["hello"], which means you can just directly write hello.innerText = "Hi!".

Since this may conflicts with any of the hundreds of other properties on window, it's generally not something that should be used.

Historically it wasn't too uncommon to see it, but since it doesn't work well with typescript, it's very rare now.


Replies

AlienRobotyesterday at 7:47 PM

You can make it work with typescript by declaring it as an HTMLElement without defining it.