Home >Web Front-end >JS Tutorial >jquery extracts the plain text in the element and does not include the content in span, etc._jquery

jquery extracts the plain text in the element and does not include the content in span, etc._jquery

WBOY
WBOYOriginal
2016-05-16 17:20:511445browse
Copy code The code is as follows:

var text = '';
$('div') .contents().each(function(){
if(this.nodeType === 3){
text = this.wholeText;
}
});

nodeType
元素element 1
属性attr 2
文本text 3
注释comments 8
文档document 9
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn