Open one tab at a time in accordion

后端 未结 2 1208
眼角桃花
眼角桃花 2021-01-23 16:02

I have a accordion which is working absolutely fine but what I need is to open only one tab at a time, means when one tab is opened then another tab should be closed.

Cu

相关标签:
2条回答
  • 2021-01-23 16:08

    You can also close other accordions by adding a beforeActivate callback:

    $( ".myAccordion" ).accordion({
          collapsible: true,
          active: false,
        heightStyle: "content",
        beforeActivate: function(event, ui) {
       $( ".myAccordion" ).not(this).accordion('option', 'active', false);
    }
    
    0 讨论(0)
  • 2021-01-23 16:17

    LIVE DEMO

    $("#accordion > li > span").click(function() {
        $(this).closest('li').siblings().find('span').removeClass('active').next('div').slideUp(250);
        $(this).toggleClass("active").next('div').slideToggle(250);
    });
    


    Or like: LIVE DEMO

    $("#accordion > li > span").click(function() {
        $(this).toggleClass("active").next('div').slideToggle(250)
        .closest('li').siblings().find('span').removeClass('active').next('div').slideUp(250);
    });
    
    0 讨论(0)
提交回复
热议问题