querySelector syntax error for digit only id attribute
Reported by
studdu...@gmail.com,
Feb 3 2018
|
|||
Issue description
UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Steps to reproduce the problem:
1. Construct an HTML 5 document w/ an element whose id attribute consists solely of numbers (e.g., 1234)
2. Open dev tools and navigate to the page/document
3. Select the console tab
4. Execute the following Javascript: $$('#1234')
What is the expected behavior?
It should have returned the element.
What went wrong?
SyntaxError: '#1234' is not a valid selector
Did this work before? N/A
Chrome version: 56.0.2924.87 Channel: stable
OS Version:
Flash Version: Shockwave Flash 28.0 r0
The problem is not limited to devtools. It happens in Javascript on the page. Devtools is just the easiest way to reproduce it.
So the bug is this. According to the HTML5 spec, the only restrictions on the id attribute are that it must be unique and it must contain at least one character. So the selector, "#1234", has no syntax errors but Firefox says otherwise. Additionally, calling document.getElementById('1234') returns the Element w/o issue.
,
Feb 4 2018
,
Feb 4 2018
#1 is correct. You can use attribute selector
// note quotes surrounding value portion of attribute selector
document.querySelector("[id='1234']")
See Is 111 a valid HTML id attribute or are document.querySelector() and document.querySelectorAll() correctly throwing syntax errors?
https://stackoverflow.com/questions/45519853/is-111-a-valid-html-id-attribute-or-are-document-queryselector-and-document-qu
,
Feb 4 2018
This is not a bug. The expected behaviour is for a DOMException error to be thrown, as `#1234` is not a valid CSS selector.
,
Feb 5 2018
|
|||
►
Sign in to add a comment |
|||
Comment 1 by woxxom@gmail.com
, Feb 3 2018