8

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?

BiAiB
  • 12,932
  • 10
  • 43
  • 63
  • @Bergi: wtf ? this question is 3 years old and you didn't even mention which question this is a duplicate of – BiAiB Sep 02 '14 at 08:31
  • Yes, the question is old and the answer is outdated. The duplicate is linked in the box "*This question already has an answer here: …*" at the top of your question. – Bergi Sep 02 '14 at 11:15

1 Answers1

7
  • 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
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335