Weird .. Anyway this: document.querySelector('[id="1"]')
is working. Fiddle: http://jsfiddle.net/wnd7K/2/
querySelector returns undefined string when trying to access numeric value as the ID of an element
-
23-06-2022 - |
Question
querySelector()
returns undefined string
when trying to access numeric value as the ID
of an element. I would like to use querySelector()
method over others, because it is more flexible.
Any solutions to this problem would be a great help.
var foo = document.querySelector('#1');
console.log(foo);
Solution
OTHER TIPS
Renaming the ids of the elements so that they begin with a letter solves your problem e.g. :
<div id="a1"></div>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow