Javascript fumction for client side HTML encode and decode
function htmlEncode(value){
return $(‘<div/>’).text(value).html();
}
function htmlDecode(value){
return $(‘<div/>’).html(value).text();
}
how its works…….
The div element is created bit it is never appended to the HTML document
use of .html(): Get the HTML contents of the first element in the set of matched elements or set the HTML contents of every matched element.
use of .text(): Get the combined text contents of each element in the set of matched elements, including their descendants, or set the text contents of the matched elements.
function htmlEncode: set the innerText of the element, and retrieve the encoded innerHTML
function htmlDecode: set the innerHTML value of the element and the innerText is retrieved.
Nice one