0
我似乎無法得到一個前置的跨度來找到它的父親李...它不應該找到它,不管它們是不是相同的標籤嗎?jquery .next找不到兄弟
這裏的前置,在CSS中它漂浮在列表項的內容的右側,但是這不應該影響它的權利?
$('aside ul > li').prepend('<span class="icon-arrow-right"></span');
和這裏的點擊功能,似乎不正確產生警報:
$('aside .icon-arrow-right').click(function(){
if($(this).next('ul').hasClass('sub-nav')) {
alert('yes');
} else {
alert('no');
}
});
此功能的當前結果總是會彈出一個「不」,不管該列表項具有帶有分類導航的子UL。
編輯:這裏是HTML,請注意JS增加了跨度,它本身不存在:
<ul>
<li><span class="icon-arrow-right"></span><a href="#">Accommodations</a>
<ul class="sub-nav">
<li><span class="icon-arrow-right"></span><a href="">Inland View Rooms</a></li>
<li><span class="icon-arrow-right"></span><a href="">Partial Ocean View Rooms</a></li>
<li><span class="icon-arrow-right"></span><a href="">Harbor View Rooms</a></li>
<li><span class="icon-arrow-right"></span><a href="">Ocean View Rooms</a></li>
<li><span class="icon-arrow-right"></span><a href="">ADA Accessible Guestroom</a></li>
<li><span class="icon-arrow-right"></span><a href="">Executive Suites</a></li>
<li><span class="icon-arrow-right"></span><a href="">Spa Terrace Suite</a></li>
<li><span class="icon-arrow-right"></span><a href="">Cannery Row Suite</a></li>
<li><span class="icon-arrow-right"></span><a href="">Grand Bay Suite</a></li>
<li><span class="icon-arrow-right"></span><a href="">Presidential Suite</a></li>
</ul>
</li>
<li><span class="icon-arrow-right"></span><a href="#">Hotel</a></li>
<li><span class="icon-arrow-right"></span><a href="#">Destination</a></li>
<li><span class="icon-arrow-right"></span><a href="#">Dining</a></li>
<li><span class="icon-arrow-right"></span><a href="#">Spa</a></li>
<li><span class="icon-arrow-right"></span><a href="#">Meetings & Events</a></li>
<li><span class="icon-arrow-right"></span><a href="#">Weddings</a></li>
<li><span class="icon-arrow-right"></span><a href="#">Packages</a></li>
<li class="book-header"><span class="icon-arrow-right"></span><a href="#">Book Now</a></li>
什麼是HTML看起來像你做'prepend'過嗎? – Barmar
你可以做一個[Stack Snippet](http://meta.stackoverflow.com/questions/270944/feedback-requested-stack-snippets-2-0)來證明這個問題嗎? – Barmar
我已經添加了UL列表的html。 – Xero1