I ran into an error with the document.querySelector() function when using a specific type of id in an element. When the id is canvas-= then the querySelector fails with an error -> Failed to execute 'querySelector' on 'Document': '#canvas-=' is not a valid selector.
But when I use document.getElementById(), it works. I can use "[id='canvas-=']" inside querySelector but why is it failing on document.querySelector("#canvas-=")?
document.querySelector("#canvas-=")
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p id="canvas-=">This is a paragraph.</p>
<script>
const elem = document.querySelector("#canvas-=");
console.log(elem.innerHTML);
</script>
</body>
</html>
document.getElementById("canvas-=")
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p id="canvas-=">This is a paragraph.</p>
<script>
const elem = document.getElementById("canvas-=");
console.log(elem.innerHTML);
</script>
</body>
</html>
But everything works fine if I remove = from the id. It doesn't work in any way you insert it. ==-, =-, -= all of these give the error. So what is wrong with the = symbol in this and why does the second method works but the first doesn't?