I have a jQuery with the following code:
id = 100;
name = "O'Keefe";
str = "<button type='button' onclick='selName( "+id+",\""+name+"\")'>Select</button>";
str is loaded into a div.
When I inspect the page it shows:
<button type="button" onclick="selName( 100, "O" Keefe")'>Select</button>
I tried escaping the single quote with
name = name.replace(/'/g, '\'');
But it didn't work.
My code works fine for names without single quote.
Any suggestions on how to deal with names with single quote?
Thanks.
'inside an attribute if you're using'as the attribute value delimiter.`