使用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();