Decode HTML entities with jQuery

Decoding HTML entities can be so easy with jQuery. The following code snippet converts all HTML entities to their applicable characters:

var encoded = "" ' & < >";
alert(encoded);
var decoded = $('<textarea />').html(encoded).val();
alert(decoded);

or

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

Share this

The Author

admin - Hello, my name is Simon, I’am 25 and I’m a software and web developer. My interests span all aspects of programming and development, including ASP, JavaScript, AJAX, PHP, .NET, Java, C#, C++, Objectv-C, Flash, Cocoa, SQL, XML and everything in between. www.simra.ch

Leave a Reply

*
 
© 2010 onYou GmbH. All Rights Reserved