[whatwg] [WHATWG] HTMLElement ids as global object properties

My biggest nightmare today is that recent browsers like Chrome, IE9, FF4 generate a global variable from the id of each HTMLElement of the document...

(even for Meta in the Head of the document)

It is know possible in these browser to write

domNode = myPanel;

or

domNode = window.myPanel;

instead of

domNode = document.getElementById('myPanel');

or with jQuery:

domNode = $('#myPanel');

Note that this behavior is not part of HTML4
http://www.w3.org/TR/1999/REC-html401-19991224/struct/global.html#adef-id
http://www.w3.org/TR/1999/REC-html401-19991224/types.html#type-name

It is neither part of HTML5
http://www.w3.org/TR/html5/elements.html#the-id-attribute


Let's imagine the effects of existing HTMLElements with id like "location", "document", "event", "toolbar", or even "window"...

What should be the list of reserved keywords for valid id value ?
All the BOM API ?
+ APIs like Web Storages, Web Sockets... ?
+ Global namespaces of common Ajax frameworks ?

And what about future HTML5/W3C APIs ?
And what about future or private frameworks ???


One of the main best practices in JavaScript development is "Don't pollute the global namespace"
It is even one of the key part of the strict mode of ECMAScript 5

The values given to ids of an HTML document is part of the business logic of the web interface
Developers are encouraged to use a single global variable as their application specific namespace

if  "document.getElementById()" is too long, why not coming back to the IE4 form "document.all()"

I would be more comfortable with at least a standard namespace global property like "elements" on window than the current situation


Thoughts ?

Alexandre




Alexandre Morgaut
Product Manager

4D SAS
60, rue d'Alsace
92110 Clichy
France

Standard : +33 1 40 87 92 00
Email :    Alexandre.Morgaut at 4d.com
Web :      www.4D.com

Received on Friday, 1 April 2011 00:26:52 UTC