+3  A: 

That's HTML Encoding. There's no native javascript function to do that, but you can google and get some nicely done up ones.

E.g. http://sanzon.wordpress.com/2008/05/01/neat-little-html-encoding-trick-in-javascript/

EDIT:
This is what I've tested:

var div = document.createElement('div');
  var text = document.createTextNode('<htmltag/>');
  div.appendChild(text);
  console.log(div.innerHTML);

Output: &lt;htmltag/&gt;

o.k.w
Too bad, I'll just have to use a custom function then.
Bart van Heukelom
You can try the method in the link I've included in my post. Pretty neat concept indeed.
o.k.w
@o.k.w: Ok, first you linked to this: http://www.yuki-onna.co.uk/html/encode.html which does exactly what `encodeURIComponent` does and not at all what the OP asked. So can you edit please? I can't seem to undo my -1.
Crescent Fresh
Yah, that page's code looks logical but I didn't test it out. The new link though works, I've verified it myself. I've already updated the post some time back.
o.k.w
@o.k.w.: yeah, edit it again please (anything minor). I can't undo my vote otherwise.
Crescent Fresh
@Crescent: done! Thanks!
o.k.w
A: 

With jQuery it can be like this:

var escapedValue = $('<div/>').text(value).html();

From related question http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery

Sasha Yanovets