jquery只获取自身文本节点,不获取子元素的

jQuery.text()方法时候,会把子元素的文本也获取到,以下方法可获取自身文本节点,不包括子元素

<div id="demo">只获取我<a href="">别管我</a></div>

var a = $ ("#demo").prop ('firstChild').nodeValue;
console.log(a);
<div id="demo">只获取我<a href="">别管我</a></div>

var a = document.getElementById('demo').firstChild.nodeValue;
console.log(a);
原文地址:https://www.cnblogs.com/juicy-initial/p/9868440.html