Javascript Encode Decode Html

by Francis 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('&Pi;')
Output Value : &amp;Pi;

2. Decode HTML Entities
function htmlDecode(val)
 {
    if (val) {
        return $('<div />').html(val).text();
    } else {
        return '';
    }
}

Input Value :  htmlDecode('&amp;Pi;')
Output Value : &Pi;
1265
like
0
dislike
0
mail
flag

You must LOGIN to add comments