How do I select text nodes with jQuery?

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

    For me, plain old .contents() appeared to work to return the text nodes, just have to be careful with your selectors so that you know they will be text nodes.

    For example, this wrapped all the text content of the TDs in my table with pre tags and had no problems.

    jQuery("#resultTable td").content().wrap("
    ")
    

提交回复
热议问题