2016-11-16 18 views
1

這讓我想起了一個循環。所以我想只能滑動頁面上的下一個<table>。現在我已經嘗試了所有的東西,但是它沒有工作,我沒有想法。切換下表中的內容

這裏是鏈接到代碼:

jsfiddle link

$(document).ready(function() { 
    $('.toggle-step').on('click', function() { 
     $(this).parent().next('table').slideToggle("fast"); 
     $(this).find('span').slideToggle(0); 
    }); 
}); 

<div class="table-wrapper"> 
    <ul class="nav nav-pills"> 
     <li class="active"> 
      <a class="toggle-step">Toggle Table <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true" style="display: inline-block;"></span> <span class="glyphicon glyphicon-triangle-right" aria-hidden="true" style="display: none;"></span> </a> 
     </li> 
    </ul> 

    <table> 
     ... 
    </table> 
</div> 
+0

'.parent()'只上升在DOM – j08691

+0

這引出了一個問題一個級別可能我已經做了.parent的next()。下一個()()? – zemaker

+0

不,因爲.parent()讓你從錨點移動到列表項目 – j08691

回答

0
$(this).closest('ul').next('table').slideToggle("fast"); 

因爲你的鏈接的父母不表的兄弟姐妹,你需要修改DOM遍歷。而且由於列表不是鏈接的父級,所以您需要使用closest()

Fiddle

+0

確實足夠了,工作正常。我無法開始告訴你我試過的所有組合,從來沒有想過要這樣做.closest('ul') – zemaker