According to the document here: https://developer.mozilla.org/en-US/docs/Web/API/document.querySelector#Notes
It says some characters need to be escaped when doing q
If it is possible, you can use this solution, albeit not cross-browser (all modern browsers except IE) - https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape
CSS.escape(".foo#bar") ->"\.foo\#bar"