Be careful what you ask for.
You're looking at the escape sequence for single quote. If you throw it onto the page, it'll display properly.
On the other hand, if you insist on converting it to an actual single quote character, you could run into problems.
Check out this code snippet to see the consequences:
<INPUT Value="Mc'Dought">
<BR>
<INPUT Value="Mc'Dought">
<BR>
<SPAN>Mc'Dought</SPAN>
<BR>
<SPAN>Mc'Dought</SPAN>
<BR>
<INPUT Value='Mc'Dought'> <!-- Problems!! -->
<BR>
<SPAN>Mc'Dought</SPAN>
However, if you understand all this and still want to unescape it (e.g. you need to use the string to set the window title
or issue an alert
), I'd suggest you use an accepted HTML-unescape method, rather than replacing just '. See this answer.
Jquery:
function escapeHtml(unsafe) {
return $('<div />').text(unsafe).html()
}
function unescapeHtml(safe) {
return $('<div />').html(safe).text();
}
Plain Javascript:
function unescapeHtml(safe) {
return safe.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, "'");
}