Javascript String html()

Description

Javascript String html()




// html escape a string
String.prototype.html = function () {
    var string = new String(this);
    string = string.replace(/\&/g, "&");
    string = string.replace(/\</g, "&lt;");
    string = string.replace(/\>/g, "&gt;");
    string = string.replace(/"/g,  "&quot;")
    string = string.replace(/'/g,  "&#39;");
    //from  w w w  .  j  a v a 2 s. c o  m
    return string
}

Javascript String html()

String.prototype.html = function() {
 return $('<i></i>').text(this).html();
};



PreviousNext

Related