views:

20

answers:

2

The following question is a good rundown on what the spec says about the contents of the id attribute: http://stackoverflow.com/questions/1077084/what-characters-are-allowed-in-dom-ids

my question is, how well do browsers adhere to this spec? I am pretty sure that i can use all numeric ids in firefox for example.

A: 

What is the purpose of this question? You clearly realize it is not a good idea. Many browsers allow invalid code to be written because they don't want to serve damaged pages to users.

You shouldn't do it, because there's a strong chance it will break yesterday, today, and certainly tomorrow. So there's no need to ask about it.

js1568
the purpose of this question is to find the answer. the answer above you claims that this will work tomorrow because of HTML5, also you assume i am working on a public facing website.
mkoryak
my point is that if there is uncertainty, why play in its shadows? Following established guidelines eliminates the need to worry about these cases.
js1568
A: 

That's the difference in HTML4 vs HTML5.

As this answer says, id's in HTML4 were highly restrictive on what is allowed.

A valid id in HTML4 as per the spec,

must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

HTML5 is a lot more relaxed with id's. A valid id as per the HTML5 spec,

must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.

Since browsers are transitioning to HTML5 (most have already implemented these basics), you might find that most modern browsers will adhere to the HTML5 way of defining ids. Still the best way is to test it out or have backing documentation to know exactly which browsers do and don't work.

Anurag