HTML Encode

HTML Encode

I have a general knowledge about jQuery syntax but I can't figure out how this piece of code works:

  1.         function htmlEncode(value) {
  2.             var encodedValue = $('<div />').text(value).html();
  3.             return encodedValue;
  4.         }
Can someone please clarify this to me?

If seems in first step it select all closed <div /> tags in the page (what???!!!) then it set its text to value (what???!!!) and in final step it return html markup of <div /> + value. (WHAT????!!!!!!!!!!)
It doesn't make any sense.

Computer Enterprise Masoud Keshavarz
For more information contact masoudk1990@yahoo.com