Cookie Consent by Free Privacy Policy Generator Encode string to HTML entities via jQuery | Igor Moiseev

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()


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

The jQuery magic! is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means to earn fees when linking to and affiliated sites.