Decode html-entities using jQuery
by Tushar Gupta
HTML
<div id="test"><code>&lt;div id='asd'&gt;asd&lt;/div&gt;</code> to <code><div id='asd'>asd</div></code>
JavaScript
var str = $('#test').html($('#test').html()).text();
function decode_str(str) {
pos = str.indexOf('<');
while (pos >= 0) {
str = str.replace('<', '<')
pos = str.indexOf('<');
}
pos = str.indexOf('>');
while (pos >= 0) {
str = str.replace('>', '>')
pos = str.indexOf('>');
}
return $.trim(str);
}
console.log(decode_str(str));
$('#test').html(decode_str(str));