Javascript Encode Decode Html
by Francis[ Edit ] 2014-07-30 16:14:07
Javascript Encode and Decode Html
Simple Tips to Encode and decode the html entities
1. Encode HTML Entities
function htmlEncode(val)
{
if (val) {
return $('<div />').text(val).html();
} else {
return '';
}
}
Input Value : htmlEncode('Π')
Output Value : &Pi;
2. Decode HTML Entities
function htmlDecode(val)
{
if (val) {
return $('<div />').html(val).text();
} else {
return '';
}
}
Input Value : htmlDecode('&Pi;')
Output Value : Π