I'm trying to look for a certain html element by its ID, which has a quotation mark in it. When the script looks for the element it throws this error:
Uncaught Error: Syntax error, unrecognized expression: #Bel'Veth
In advance, I can't use another variable name.
Here's my JavaScript code:
c = "Bel'Veth"
$("#"+c).addClass("selected");
My HTML:
<div id="Bel'Veth">Bel'veth</div>
I already tried using c = c.replace("'", "\'")
and c = c.replace("'", "\\'")
, it results in the following errors:
Uncaught Error: Syntax error, unrecognized expression: #Bel'Veth
Uncaught Error: Syntax error, unrecognized expression: #Bel\\'Veth