开发者

Why does this undefined variable refer to an element's id

<div id="myDiv"></div>

alert(myDiv); // alert开发者_开发百科s '[html HTMLDivElement]'

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜