This question already has an answer here:
- Unescape HTML entities in Javascript? 10 answers
How do I encode and decode HTML entities using JavaScript or JQuery?
var varTitle = "Chris' corner";
I want it to be:
var varTitle = "Chris' corner";
Inspired by Robert K's solution, this version does not strip HTML tags, and is just as secure.
Because @Robert K and @mattcasey both have good code, I thought I'd contribute here with a CoffeeScript version, in case anyone in the future could use it:
See https://jsfiddle.net/tigerhawkvok/t9pn1dn5/7/ or https://gist.github.com/tigerhawkvok/285b8631ed6ebef4446d (includes compiled JS, and is probably updated compared to this answer)
You could try something like:
JS Fiddle.
A more interactive version:
JS Fiddle.
To add yet another "inspired by Robert K" to the list, here is another safe version which does not strip HTML tags. Instead of running the whole string through the HTML parser, it pulls out only the entities and converts those.
here is another version:
I think that is the exact opposite of the solution chosen.
Try it :)