JSFiddle - React, Tailwind, and code Playground

by Sandeep Kumar

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 &amp; me are good friends'));
});