Search code examples
javascriptjqueryselectors-api

querySelector returns undefined string when trying to access numeric value as the ID of an element


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);

jsFiddle


Solution

  • Weird .. Anyway this: document.querySelector('[id="1"]') is working. Fiddle: http://jsfiddle.net/wnd7K/2/