How do I select text nodes with jQuery?

前端 未结 11 1555
独厮守ぢ
独厮守ぢ 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:13

    Can also be done like this:

    var textContents = $(document.getElementById("ElementId").childNodes).filter(function(){
            return this.nodeType == 3;
    });
    

    The above code filters the textNodes from direct children child nodes of a given element.

提交回复
热议问题