I have a string in JavaScript that contains a quote mark - for example, Don't click this checkbox
or He said "hi"
. I am trying to find a checkbox that has the exact same value.
For my first example, I have the HTML:
<input type="checkbox" value="Don\'t click this checkbox">
And my variable q has the string Don't click this checkbox
in it. To try and query for this checkbox, I have the following code. Where am I going wrong?
q = q.replace("'", "\'").replace("\"", "\\"");
var $checkbox = $("input:checkbox[value='" + q + "']");