如何隐藏兄弟姐妹元素



单击一个类别时,我将如何隐藏其余类别,如果我再次单击其余类别,则将再次出现。

<?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();
});

谢谢

基于您的代码共享

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

您正在显示行列表,因此您应该隐藏row S

$(this).closest('.row').siblings().toggle();

最新更新