_.escape(string)
This function converts the characters &, <, >, “, `, and ‘ into their HTML escaped versions &, <, >, ", ` and '
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <!DOCTYPE html> <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js"></script> <script type="text/javascript"> var str = "<html>topjavatutorial.com</html>"; var escapedStr = _.escape(str); console.log(escapedStr); </script> </head> </html> |
Output:
_.unescape(string)
The opposite of escape, replaces &, <, >, ", ` and '
with their unescaped counterparts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <!DOCTYPE html> <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js"></script> <script type="text/javascript"> var escapedStr = "<html>topjavatutorial.com</html>"; var unescapedStr = _.unescape(escapedStr); console.log(unescapedStr); </script> </head> </html> |
© 2017, https:. All rights reserved. On republishing this post, you must provide link to original post