Escape HTML (one-liner)


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. String.prototype.htmlEscape = function()
  2. {return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/\>/g,'&gt;')}
  3.  
  4.  
  5. // test it out...
  6. alert( '<a href="/?foo=1&bar=2"> blah </a>'.htmlEscape() );

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.