我的HTML:Jquery仅输出选定的html,但不输出它的子项?
<ul id="seasonsDropDown">
<li>FALL 2013 HAUTE COUTURE
<ul class="designers">
<li>Alexander Wang</li>
<li>BCBG MAX Azria</li>
<li>Diane con Fursternberg</li>
<li>Diane Von De</li>
</ul>
</li>
<li>SPRING 2013 HAUTE COUTURE</li>
<li>SPRING 2033 HAUTE COUTURE</li>
<li>SPRING 2093 COUTURE</li>
什么jQuery的方法,我应该使用,如果我只是想选择/输出字:
"FALL 2013 HAUTE COUTURE"
不是UL名单?
现在如果我使用:
console.log($("#seasonsDropDown").html());
它会给我一切,包括HTML。
它看起来像这个问题是一个重复:http://stackoverflow.com/questions/3442394/jquery-使用文本检索只有文本没有嵌套在子标签 –
请参阅$('#seasonsDropDown li:first')。contents()。filter(function(){ return this.nodeType == 3 })。text()'like http://jsfiddle.net/arunpjohny/y4D25/1/ –