Skip to content

Instantly share code, notes, and snippets.

@hackerxian
Created March 4, 2016 07:13
Show Gist options
  • Save hackerxian/714b02772522cdb26b34 to your computer and use it in GitHub Desktop.
Save hackerxian/714b02772522cdb26b34 to your computer and use it in GitHub Desktop.
获取标签内部的文本内容但是不获取该标签中的其他标签的文本
<div>
    <p>内容<span>我不获取的内容</span>内容</p>
</div>
var str = $('div p').contents().filter(function (index, content) {
    return content.nodeType === 3;
}).text();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment