我的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/ –