How to return querySelectorAll for IDs starting with a number

Viewed 19

JavaScript function querySelectorAll() fails on Chrome when the IDs begin with a number.

For example, querySelectorAll("#A5") succeeds, but querySelectorAll("#5A") returns

Error:

"Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Element': '#5A' is not a valid selector."

I understand that an ID starting with a number is valid in HTML5 so I wondered if anyone knows of another way to query for it.

I tried querySelectorAll("#5A") and expected the query to include the element with an id set to "5A"

I realise I can just use "document.getElementById()" to find one element, but I want to include it in a multi-element query in the DOM.

0 Answers
Related