Remove text with jQuery

后端 未结 5 894
生来不讨喜
生来不讨喜 2020-11-27 06:59

Is there a way to remove text that is not wrapped in any tag using jQuery

This is some text

This is \"unwrapped\" text //to be removed &
5条回答
  •  青春惊慌失措
    2020-11-27 07:33

    Using the answer from this question:

    $(elem)
      .contents()
      .filter(function() {
        return this.nodeType == 3; //Node.TEXT_NODE
      }).remove();
    

提交回复
热议问题