Using .text() to retrieve only text not nested in child tags

后端 未结 25 1745
隐瞒了意图╮
隐瞒了意图╮ 2020-11-21 05:55

If I have html like this:

  • This is some text First span text
  • 25条回答
    •  花落未央
      2020-11-21 06:43

      jQuery.fn.ownText = function () {
          return $(this).contents().filter(function () {
              return this.nodeType === Node.TEXT_NODE;
          }).text();
      };
      

    提交回复
    热议问题