2
<div id="myDiv"></div> alert(myDiv); // alerts '[html HTMLDivElement]' 

I don't understand how this seems to work. I thought you must specify the div element's id with getElementById();

0

1 Answer 1

4

It only works in some browsers.

Internet Explorer does add all id's to the window object, so that you can access them directly. Most other browsers doesn't.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.