Billy Bo the HTML Blob

Billy Bo Bob the HTML Blob.

An HTML, CSS and JavaScript Odyssey.

Remove reserved characters from a text string.

How do you remove all reserved HTML characters from a string and replace them like the following:


If you want to do this you can make a JavaScript function like:

var cleanHtmlText = function (dirtyCode) {
    return dirtyCode.replace(/&/g, "&")
                    .replace(/"/g, """)
                    .replace(/'/g, "'")
                    .replace(/</g, "&lt;")
                    .replace(/>/g, "&gt;");
};

You can see the instruction video at youtube by clicking on this text here. To see how it works: Play around!