How do I select text nodes with jQuery?

前端 未结 11 1766
独厮守ぢ
独厮守ぢ 2020-11-21 04:30

I would like to get all descendant text nodes of an element, as a jQuery collection. What is the best way to do that?

11条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-21 05:00

    if you want to strip all tags, then try this

    function:

    String.prototype.stripTags=function(){
    var rtag=/<.*?[^>]>/g;
    return this.replace(rtag,'');
    }
    

    usage:

    var newText=$('selector').html().stripTags();
    

提交回复
热议问题