How to decode HTML entities using jQuery?

EddyR picture EddyR · Jul 18, 2009 · Viewed 330.4k times · Source

How do I use jQuery to decode HTML entities in a string?

Answer

tom picture tom · Mar 10, 2010

Security note: using this answer (preserved in its original form below) may introduce an XSS vulnerability into your application. You should not use this answer. Read lucascaro's answer for an explanation of the vulnerabilities in this answer, and use the approach from either that answer or Mark Amery's answer instead.

Actually, try

var decoded = $("<div/>").html(encodedStr).text();