Encode string to HTML entities via jQueryedit
27 Feb 2015
1 min
The follwoing will encode your string to HTML
entities
jQuery('<div />').text('Some text with <div>html</div>').html()
and the output will look like
"Some text with <div>html</div>"
To decode we just switch methods
jQuery('<div />').html('Some text with <div>html</div>').text()
produces
"Some text with <div>html</div>"
The jQuery magic!