Monday, November 15, 2010

HTML Encode Decode in Javascript/jQuery


Last day, I had a resolute and unyielding need to HTML Decode a string.
I saw many solutions but was not satisfied.
Then I found the StackOverFlow reference which is the most optimal solution I have seen till date. Just pasting it here for easy reference.

function htmlEncode(value){ 
  return $('<div/>').text(value).html(); 
} 

function htmlDecode(value){ 
  return $('<div/>').html(value).text(); 
}


Did I say jQuery? I sure did say optimal :P
Happy Coding!

Dependency: jQuery

Related Posts :



0 comments on "HTML Encode Decode in Javascript/jQuery"

Add your comment. Please don't spam!
Subscribe in a Reader

Post a Comment