I have an HTML tag with the name foo\bar and when trying to get the selector by id name it returns null:
<html>
<body>
<div id="foo\bar">a</div>
<script>
var esc = document.querySelector('#foo\\bar');
console.log(esc); //returns 'null'
</script>
</body>
</html>
Not sure why this happens, when logging #foo\\bar to the console it perfectly outputs the correct id of the tag:
console.log("#foo\\bar");
var esc = document.getElementById('foo\\bar');
Use getElementById instead of querySelector.
<html>
<body>
<div id="foo\bar">a</div>
<script>
var esc = document.getElementById('foo\\bar');
console.log(esc); //returns '<div id="foo\\bar">a</div>'
</script>
</body>
</html>