css jquery hide one div, show another

前端 未结 7 1016
遥遥无期
遥遥无期 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:53

    This is a very simple principle...you can achieve it many ways, this is just one example.

    Ignore the selectors, I'm lazy.

    The HTML ->

     Show Div 1  |  Show Div 2 
    

    Div 1
    Div 2

    The CSS ->

    #div1{
      display:none;   
    }
    

    The jQuery ->

    $('a:eq(0)').click(function(){
      $('#div1').toggle();
      $('#div2').toggle();    
    });
    $('a:eq(1)').click(function(){
      $('#div2').toggle();
      $('#div1').toggle();   
    });
    

提交回复
热议问题