Wednesday, October 3, 2007

A simple effective HTML-escape/encode function in Javascript!

At LUNARMEDIA I found this function below will take a string and return a HTML-encoded version of it!

function escapeHTML (str)
{
var div = document.createElement('div');
var text = document.createTextNode(str);
div.appendChild(text);
return div.innerHTML;
};

No comments: