Closed Bug 718326 Opened 14 years ago Closed 14 years ago

querySelector fails on numerical ids

Categories

(Core :: General, defect)

9 Branch
x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: james.r.campos, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7 Steps to reproduce: document.querySelector('#1') Actual results: [Exception... "An invalid or illegal string was specified" code: "12" nsresult: "0x8053000c (NS_ERROR_DOM_SYNTAX_ERR)" location: "Web Console Line: 1"] Expected results: the element with id '1' should have been returned. html5 allows ids beginning with numbers - http://www.w3.org/TR/html-markup/datatypes.html#common.data.id-def
> html5 allows ids beginning with numbers Yes, but CSS does not allow ID selectors beginning with numbers, and the string passed to querySelector uses CSS selector syntax. Simple testcase: <!DOCTYPE html> <style> div { color: green; } div#1 { color: red; } div#\32 { color: purple; } </style> <div id="1">Some green text</div> <div id="2">Some purple text</div> In particular, document.querySelector('#\\31') will do what you want. I just checked, and all three of Gecko, Presto, and WebKit get all of this right.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.