jquery 如何获取标签自己的文本内容,不包含子元素

 <li><a href="http://gz.ihk.cn/esf/houselist/?lp=保利花园" ><strong id="aaaa">保利花园<b>海珠 工业大道中</b></strong></a></li>html

本人想要获取保利花园node

实现方法:code


一:htm

var obj = $("#aaaa").clone();
obj.find(':nth-child(n)').remove();
console.log(obj.html());

 

二:rem

var str = $('#aaaa').contents().filter(function (index, content) {

    return content.nodeType === 3;

}).text();
相关文章
相关标签/搜索