Comment on JavaScript: Difference Between GetElementByID and QuerySelectorparentComments−kiru_ioOP2yInteresting difference but why is querySelector(`#${CSS.escape(id)}`) better?The linked SO[0] link answers the question: Basically, you can have an id starting with a number, but have to escape them correctly.I was mostly surprised to learn there is a difference between CSS selectors and the querySelector in Javascript.[0] https://stackoverflow.com/a/20306237−65102yI'm mostly surprised we have different rules for id's in html5 and css.That you can hack something up that will accept numbers is no surprise. You could use getAttribute or xpath, I'm sure those will accept numbers too.
Comments
The linked SO[0] link answers the question: Basically, you can have an id starting with a number, but have to escape them correctly.
I was mostly surprised to learn there is a difference between CSS selectors and the querySelector in Javascript.
[0] https://stackoverflow.com/a/20306237
I'm mostly surprised we have different rules for id's in html5 and css.
That you can hack something up that will accept numbers is no surprise. You could use getAttribute or xpath, I'm sure those will accept numbers too.