Encode or Decode html entity from string

Decoding the HTML entity

var entityString = "<strong>Am Asik</strong>";
var entityDecodedString = $('<div />').html(entityString).text();
alert(entityDecodedString ); //<strong>Am Asik</strong>

 

Encoding the HTML entity

var entityString = "<strong>Am Asik</strong>";
var entityEncodedString = $('<div />').text(entityString).html();
alert(entityEncodedString); //&lt;strong&gt;Am Asik&lt;/strong&gt;

 

Leave a Reply

Your email address will not be published. Required fields are marked *