How to get text inside of container that is not part of children

后端 未结 3 1133

Let\'s have html code like this:

1.Hallo Kitty,
How are you?
<
3条回答
  •  花落未央
    2021-01-06 06:33

    Improving on halex's trick, you can take advantage of the fact that .children() finds only DOM nodes and ignores text nodes:

    var text = $('#d1').clone().children().remove().end().text(); // string "Hallo "
    

    ...but I prefer the .nodeType technique, because it's more clear what you're doing.

提交回复
热议问题