Answers for "how to escape string in html"

10

html escape characters

Escapes or unescapes an HTML file removing traces of offending characters that could be wrongfully interpreted as markup.

The following characters are reserved in HTML and must be replaced with their corresponding HTML entities:

" is replaced with "
& is replaced with &
< is replaced with &lt;
> is replaced with &gt;
Posted by: Guest on April-23-2020
0

javascript escape html string

//escaping HTML with jquery
var dangerousHTML = "<script>alert('Badabing Baby!');</script>";
$("#myElementID").text(dangerousHTML); //.text() function will escape and display text


//Alternatively, here is plain Javascript escape function
function escapeHtml(str) {
    return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
}
Posted by: Guest on July-31-2019

Browse Popular Code Answers by Language