使用jQuery选择不在元素中的文本

使用jQuery选择不在元素中的文本

问题描述:

说我有这个:

<div class='myDiv'>
    <p>hello</p>
    hello
    <p>Hello</p>
</div>

一个人如何使用jQuery抓取两个P标签之间的文本问候?

How does one grab the text hello between the two P tags using jQuery?

$('.myDiv')
  .contents()
  .filter(function() {
    return this.nodeType == Node.TEXT_NODE;
  }).text();

如何使用jQuery选择文本节点?

http://jsfiddle.net/6us8r/