Remove image elements from string

前端 未结 8 2287
独厮守ぢ
独厮守ぢ 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:37

    You could load the text as a DOM element, then use jQuery to find all images and remove them. I generally try to treat XML (html in this case) as XML and not try to parse through the strings.

    var element = $('

    My paragraph has images like this and this

    '); element.find('img').remove(); newText = element.html(); console.log(newText);

提交回复
热议问题