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

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

本人想要获取保利花园

实现方法:


一:

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

二:

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

    return content.nodeType === 3;

}).text();

猜你喜欢

转载自my.oschina.net/u/2494395/blog/1933100