JSFiddle - React, Tailwind, and code Playground
JavaScript
function encodeHTML(text) {
if (text) {
return jQuery('<div />').text(text).html();
} else {
return '';
}
}
function decodeHTML(text) {
if (text) {
return $('<div />').html(text).text();
} else {
return '';
}
}
$(function () {
//pass the html to encode.
alert(encodeHTML('You & me are good friends'));
//pass the html to decode.
alert(decodeHTML('You & me are good friends'));
});