Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple HTML encoding/decoding using jQuery
function htmlEncode(value){
return $('<div/>').text(value).html();
function htmlDecode(value){
return $('<div/>').html(value).text();

This comment has been minimized.

Copy link

@Lukenickerson Lukenickerson commented Dec 15, 2016

A more reliable method is to use .replace to replace the problematic characters, as shown in this example and used by Angular. See this article for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment