Igor Moiseev Applied mathematician, Web Developer

Encode string to HTML entities via jQueryedit

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 &lt;div&gt;html&lt;/div&gt;"

To decode we just switch methods

jQuery('<div />').html('Some text with &lt;div&gt;html&lt;/div&gt;').text()

produces

"Some text with <div>html</div>"

The jQuery magic!