This question already has an answer here:
Assume that I have a <li id="gen__1002_____46.14_li">
I want to select this li
.
To be able to achieve it, I wrote,
var id="gen__1002_____46.14_li";
document.querySelector("#" + id);
But querySelector returns as;
Failed to execute 'querySelector' on 'Element': '#gen__1002_____46.14' is not a valid selector.
When id
does not include dot
character, it selects correctly.
My question is, how can I select a html dom elements where its id includes .
char. Is there any restriction that id cannot include .
char.
Is there any solution for me rather than removing .'s in ids.
You need to escape the dot
And in pure js:
EDIT
If you just want to select element by id, use
getElementById()