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

前端 未结 1 799
暖寄归人
暖寄归人 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%;
    }
    
    
    
    droite1
    gauche1
    droite2
    gauche2
    droite3
    gauche3
    droite4
    gauche4

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