Encode string to HTML entities via jQuery
Encode to HTML entities
jQuery('<div />').text('Some text with <div>html</div>').html()
produces
"Some text with <div>html</div>"
To decode we just switch the methods
jQuery('<div />').html('Some text with <div>html</div>').text()
produces
"Some text with <div>html</div>"
Related protips:
Written by Igor Moiseev
Related protips
2 Responses
you may also want to check alternatives and their comparison here: http://jsperf.com/htmlencoderegex/25
over 1 year ago
·
thanks!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Html
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#