MadeInDreams
MadeInDreams

Reputation: 2126

Numbers as ID in web pages isnt working!

I was just wondering why my jquery event woudlnt be triggerd in FireFox when im using Numeric Values in my ID tags

Like ($"#2").live .....

and <div id='2' .....

ive noticed that the events arent triggerd this way and only in FireFox. Any explanation is welcome.

Upvotes: 0

Views: 189

Answers (4)

Boris Zbarsky
Boris Zbarsky

Reputation: 35074

It really depends on what ($"#2") is doing. If it's passing #2 to a querySelector call, for example, that would fail because that's not a valid CSS selector.

I suspect you're using some sort of library that does something like that; it might work in other browsers due to bugs in their CSS selector parsers or due to the library doing browser-sniffing and not running the same code in those other browsers.

Upvotes: 0

David Thomas
David Thomas

Reputation: 253396

ID and NAME tokens 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 ("."). Citation: html 4 reference at the W3.

So your id is not valid, as it starts with a numeric character.

Under HTML 5 however the id is only required to have:

The id attribute specifies its element's unique identifier (ID). The value 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.

Upvotes: 4

jake
jake

Reputation: 1939

ID values for html elements 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 (".").

Upvotes: 0

user113716
user113716

Reputation: 322542

It isn't valid HTML4 to have IDs that begin with a number.

You must start them with a letter.

Numeric IDs are allowed in HTML5 though.

Upvotes: 2

Related Questions