2013-04-02 66 views
0

我使用這個jQuery來選擇下一個列表元素並克隆類.slide-title然後將它附加到另一個類。jQuery .next選擇器沒有找到類

$('li:visible').next('.slide-title').clone().appendTo('.feat_next');

這是HTML和jsfiddle如果我從.next()功能它克隆了一個列表元素,並追加它刪除選擇。那麼爲什麼不找到.slide-title課?

感謝

<ul id="slider" style="position: relative;"> 
    <li style="position: absolute; top: 0px; left: 0px; display: block; z-index: 4; opacity: 1;"> 
     <div class="content_left"> 
      <p class="slide-date">July 2, 2012</p> 
      <h2><a class="slide-title" href="#">3333333333</a></h2>asdfasfasfasdfasdfasdfasdfasfdasfdasfdasfd 
      <p class="post-byline">by admin</p> 
     </div> 
     <div class="img_right"><a href="#"><img src="#"></a> 
     </div> 
    </li> 
    <li style="position: absolute; top: 0px; left: 0px; display: none; z-index: 2; opacity: 0;"> 
     <div class="content_left"> 
      <p class="slide-date">April 1, 2013</p> 
      <h2><a class="slide-title" href="#">asdfasdfasdf</a></h2>asdfasfasdfasdfasdf 
      <p class="post-byline">by admin</p> 
     </div> 
     <div class="img_right"><a href="#"><img src="#"></a> 
     </div> 
    </li> 
    <li style="position: absolute; top: 0px; left: 0px; display: none; z-index: 1; opacity: 0;"> 
     <div class="content_left"> 
      <p class="slide-date">April 2, 2013</p> 
      <h2><a class="slide-title" href="#">223234234</a></h2>asdfasfdasfasfasfasdfasdf 
      <p class="post-byline">by admin</p> 
     </div> 
     <div class="img_right"><a href="#"><img src="#"></a> 
     </div> 
    </li> 
</ul> 
     <div class="feat_next"><a href="#"></a></div> 
     <div class="feat_prev"><a href="#"></a></div> 

回答

2

.next()將獲得一個同級它必須是一個li。然後,您可以使用.find()來檢查元素的後代。

$('li:visible').next('li').find('.slide-title').clone().appendTo('.feat_next'); 
0

檢查the docs.next()只能找到所選元素的下一個兄弟。您將需要使用.find()來檢索您的內容。