Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 1
    Love it, works for me, tested it in the Chrome console and indeed the <script> tags and any attributes it had are removed completely. Commented Oct 22, 2015 at 19:12
  • 1
    I also prefer this solution. A pure JavaScript way to do it is creating a div with var div = document.createElement('div'); and then setting innerHTML and getting innerText to unescape; vice-versa for escaping. Commented Aug 6, 2017 at 14:44
  • jQuery text() will strip html if it's invalid, like for ex. when using table rows. Commented Aug 24, 2022 at 0:12