How do I use JQuery to remove all “script” tags in a string of HTML?

后端 未结 4 442
离开以前
离开以前 2020-12-09 04:15

Suppose I have a string of HTML code. I want to use JQuery to remove all

4条回答
  •  孤街浪徒
    2020-12-09 05:04

    Old question, but if you are still looking for the easiest way to remove scripts from a string try

    $.parseHTML(string);  
    

    $.parseHTML() automatically removes script tags from strings.

    Edit:

    This works because keepScripts has false value as default. (Reference: $.parseHtml)

    $.parseHTML(data, context, keepScripts)
    

提交回复
热议问题