2017-11-30 19 views
0

クリックすると残りのカテゴリを隠す方法と、もう一度クリックするとカテゴリの残りの部分が再度表示されます。兄弟要素を非表示にする方法

<?php if($slide1_row_cnt > 0){ ?> 
<div class="item active"> 
<h4>Groups</h4> 
    <?php while ($row = mysqli_fetch_assoc($slide1_result)) { ?> 
     <div class="row"> 
      <div class="col-xs-2"> 

       <p class="groups-list"><button type="button" class="btn btn-primary groups-button" rel="/tasks/stock/stock-category-list.php?filter=<?php echo $row['id_stc']; ?>"><?php echo $row['description_stc']; ?></button></p> 
      </div> 
     </div> 

    <?php } ?> 
</div> 
<!-- /Slide1 --> 

Javascriptを:

$('.groups-button').click(function() { 
    $(this).parent('p').siblings().toggle(); 

}); 

おかげ

+0

親 'p'は何の兄弟を持っていない非表示にするようにするには、行のリストを示しています。 – panther

+1

.rowクラスを切り替える必要があります – LenapCapo

+0

おそらく '$(this).closest("。row ")' – mplungjan

答えて

1

あなたのコードに基づき

<?php while ($row = mysqli_fetch_assoc($slide1_result)) {

を共有しました

あなたがrow

$(this).closest('.row').siblings().toggle(); 
関連する問題