Possible Duplicate:
How to escape HTML
How can a string be converted to HTML in JavaScript?
e.g.
var unsafestring = "<oohlook&atme>";
var safestring = magic(unsafestring);
where safestring
now equals "<ohhlook&atme>"
I am looking for magic(...)
.
I am not using JQuery for magic
.
function htmlEntities(str) {
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
}
So then with var unsafestring = "<oohlook&atme>";
you would use htmlEntities(unsafestring);