Remove image elements from string

前端 未结 8 2362
独厮守ぢ
独厮守ぢ 2021-02-20 16:47

I have a string that contains HTML image elements that is stored in a var.

I want to remove the image elements from the string.

I have tried: var content =

相关标签:
8条回答
  • 2021-02-20 17:46

    Use the text() function, it will remove all HTML tags!

    var content = $("<p>"+content+"</p>").text();
    
    0 讨论(0)
  • 2021-02-20 17:52

    I'm in IE right now...this worked great, but my tags come out in upper case (after using innerHTML, i think) ... so I added "i" to make it case insensitive. Now Chrome and IE are happy.

    var content = content.replace(/<img[^>]*>/gi,"");
    
    0 讨论(0)
提交回复
热议问题