Recently I have found the need to HTML Encode text in JavaScript, especially when using update list items and Single Line Of Text or Multiple Lines Of Text fields.
An easy way to do this is use the native functionality of the browser when it processes DIV’s.
Any text inside of a DIV automatically...