document.all offers another IE quirk

To finish off a trio of posts about IE oddities, another site with subtle problems demonstrates yet another quirk.

The site uses the outdated document.all syntax.

document.all is the main collection of IE's original document object model. It contains all elements in the document, and you can access individual elements with normal JavaScript bracket notation: document.all[0] or document.all['someElementID'] .

It is less known that in addition to the normal bracket syntax one can also use round brackets – like in a function call. document.all(0) is equivalent to document.all[0]. I don't know why IE supports this, perhaps to cater for newbie JavaScript authors who don't distinguish properly between square and round brackets?

The Maltanet site uses the less familiar syntax document.all() with various arguments. Some of the arguments have the value null. It turns out that while document.all[null] is undefined (as one expects), document.all(null) returns the first element in the document!

Not suprisingly, this quirk evaded both FireFox and Opera when they implemented their document.all support. Hence the menus on this particular page will only work in IE.

Advertisements

4 thoughts on “document.all offers another IE quirk

  1. An enlightening comment by E-mail from Joshua Paine:I got to reading your miscoded journal from Scott Andrew LePera. I notice in the pages I have read that a couple times you wonder aloud why IE allows () where it should only allow [] in JavaScript. Beyond or complementing the 'embrace and extend' theory, I'm pretty confident it has something to do with making VB[Script] writers comfortable. VB, of course, is Microsoft's baby, and they seemed to hope to supplant JavaScript on web pages with VBScript. And VB uses () for indexing arrays and hashes as well as for calling functions.

  2. The solution for this would be, make document.all a function, the toString() method return "object", fill it up with the elements, and change all properties like length and bla bla bla.Then hide it :p

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s