How to build simple tabs with jQuery?

前端 未结 6 761
感动是毒
感动是毒 2020-11-29 02:58

I have the following code: fiddle

Which works great in websites I create my self and with no JS the tabs act as jump links to the relevant sections. When placed in

6条回答
  •  误落风尘
    2020-11-29 03:38

    I am guessing your website is having problems with href, i presume that when user clicks a href, website automatically eradicating itself.

    Here is new solution's jsFiddle.

    I have a new solution for you:

    updated jQuery:

    $('#tabs li a').click(function(){
      var t = $(this).attr('id');
    
      if($(this).hasClass('inactive')){ //this is the start of our condition 
        $('#tabs li a').addClass('inactive');           
        $(this).removeClass('inactive');
    
        $('.container').hide();
        $('#'+ t + 'C').fadeIn('slow');
     }
    });
    

    new html markup:

    
    
    1Some content
    2Some content
    3Some content
    4Some content

提交回复
热议问题