[thelist] What's the reasoning behind not starting IDs with a number?

Matt Warden mwarden at gmail.com
Thu Jan 11 12:37:00 CST 2007


On 1/11/07, liorean <liorean at gmail.com> wrote:
> On 11/01/07, Matt Warden <mwarden at gmail.com> wrote:
> > Would this be an issue in any instance other than the automatic
> > creation of variables based on the ID? If you always interacted with
> > the document like:
> >
> > var foo = document.getElementById("0xD");
> >
> > I don't think it would ever matter.
>
> Well, sure, that's one way of making it work for that specific use.
> But as I said, there's legacy - how about document.form.0xd - that's
> an invalid identifier, and the 0xd would be a decimal 100 anyway...

That only works if the name attribute is 0xD (which, btw, it can be
according to the HTML specs -- they fixed that in XHTML).

> How about CSS then? How would CSS handle an identifier like this, for
> example #835654? That's not an indentifier in CSS, that's a colour
> value and may not appear in selectors!

Have you tried something like this in browsers:

.1 {
    background-color: #000;
}

#000 {
    background-color: #000;
}

Both work in IE (doesn't in FF). So, somehow (context), browsers are
dealing with it anyway

Anyway, obviously these things are bad from a readability perspective.
I'm just playing devil's advocate, because I'm trying to nail down
exactly why these rules exist.

-- 
Matt Warden
Cleveland, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the thelist mailing list