css jquery hide one div, show another

前端 未结 7 1033
遥遥无期
遥遥无期 2021-01-21 22:12

I am having a challenge. I have 2 divs, one set to display:none; in the css when the page loads I have two corresponding links. When the user clicks on

7条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-21 22:50

    Here an example:

    $(function () {
      $(".div1, .div2").hide();
    
      $(".link1, .link2").bind("click", function () {
        $(".div1, .div2").hide();        
    
        if ($(this).attr("class") == "link1")
        {
          $(".div1").show();
        }
        else
        {
          $(".div2").show();
        }
      });
    
    });
    

    And here is the Demo

提交回复
热议问题