开发者

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

开发者 https://www.devze.com 2023-03-06 06:34 出处:网络
<div id=\"myDiv\"></div> alert(myDiv); // alert开发者_开发百科s \'[html HTMLDivElement]\'
<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

精彩评论

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

关注公众号