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 <
> is replaced with >
Escaping HTML characters in a string means replacing the:
1.less than symbol (<) with <
2.greater than symbol (>) with >
3.double quotes (") with "
4.single quote (') with '
5.ampersand (&) with &
------------------------------
function escape(htmlStr) {
return htmlStr.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
console.log(escape("<script>alert('hi')</script>"));
Code Example |
---|
Html :: yellow html |
Html :: how to display the first frame of the video element in html |
Html :: refused to connect iframe php |
Html :: ejs ternary |
Html :: bootstrap 5 accordion |
Html :: html image |
Html :: show scrollbar only when scrolling |
Html :: html table row span |
Html :: html scrollable table vertical |
Html :: plantuml font size |
Html :: how to add image in html |
Html :: difference between xhtml and html |
Html :: ionic skeleton |
Html :: django python variable in html |
Html :: how to change font color of h2 tag in html |
Html :: what does html stand for |
Html :: bootstrap 5 navbar not working |
Html :: change font size of input text html |
Html :: bootstrap gutter |
Html :: html table |
Html :: html scale svg |
Html :: add color to hr tag |
Html :: picsum |
Html :: bootstrap 4 button link |
Html :: html percentage |
Html :: bootstrap 4 multiple file upload |
Html :: html insert image |
Html :: get id value of html dropdown in jquery |
Html :: vuejs v-on |
Html :: html to text npm |