jQuery toggle() , button i want click on 1 button and hide all other div

前端 未结 1 798
暖寄归人
暖寄归人 2021-01-28 12:54

When I click on a particular button, I want to hide all other

s.

相关标签:
1条回答
  • 2021-01-28 13:19

    Do you want something like this? You don't need to add click handlers to each individual div. Just get the index of the button clicked and show the div with that index.

    $(document).ready(function() {
      $(".poz button").click(function() {
        var i = $(this).index();
        
        $(".fichier").hide();
        $(".fichier").eq(i).show();
      });
    });
    .fichier {
      display: none;
      position: absolute;
      top:0;
      left:0;
      height: 100%;
      width: 100%;
    }
    
    .poz {
      position: absolute;
      width: 50%;
      height: 64px;
      overflow-x: scroll;
      bottom: 0;
      right: 0;
    }
    
    .btna {
      width: 19%;
      height: 50px;
    }
    
    .droite {
      background: purple;
      float: right;
      width: 50%;
      height: 100%;
    }
    
    .gauche {
      background: orangered;
      float: left;
      width: 50%;
      height: 100%;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
    <div class="fichiers">
      <div class="fichier">
        <div class="droite">droite1</div>
        <div class="gauche">gauche1</div>
      </div>
    
      <div class="fichier">
        <div class="droite">droite2</div>
        <div class="gauche">gauche2</div>
      </div>
    
      <div class="fichier">
        <div class="droite">droite3</div>
        <div class="gauche">gauche3</div>
      </div>
    
      <div class="fichier">
        <div class="droite">droite4</div>
        <div class="gauche">gauche4</div>
      </div>
    </div>
    
    <div class="poz">
      <button class="btna">arme 1</button>
      <button class="btna">arme 2</button>
      <button class="btna">arme 3</button>
      <button class="btna">arme 4</button>
    </div>

    0 讨论(0)
提交回复
热议问题