开发者

why window[id] === document.getElementById( id ) [duplicate]

This question already has answers here: 开发者_如何学C Is there a spec that the id of elements should be made global variable? (5 answers) Closed 8 years ago.

I've noticed in several browsers, dom elements can be accessed simply by their id like this:

HTML

<div id="chocolat"></div>

JS

alert(chocolat.id); //alerts "chocolat
chocolat; //points to the node
window.chocolat; //idem
chocolat === document.getElementById('chocolat'); // true

( test here: http://jsfiddle.net/GUUPT/ ) This will work on some versions of IE, on Chrome, but it won't on Firefox(5).

I'm curious where does this come from ? is it in the standards?


  • It is non-standard
  • It was started by Internet Explorer (version 4 IIRC)
  • IIRC it only works in Quirks mode if you are using the latest version of IE
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜