css jquery hide one div, show another

前端 未结 7 1027
遥遥无期
遥遥无期 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 23:05

    Depending on your HTML structure

    if something like this

    link1
    link2
    
    div for link 1
    div for link 2

    then jQuery code would look like this

    $('a').click(function(e){
        $('div').eq($(this).index()).show();
        $('div').not($('div').eq($(this).index()).hide();
    });
    

    http://jsfiddle.net/NXdyb/

提交回复
热议问题