Trigger jquery accordion menu by an event?

前端 未结 2 847
耶瑟儿~
耶瑟儿~ 2021-02-20 04:33

Is it possible to open the next panel in a jquery accordion menu through a seperate button onclick event? That is instead of clicking the heading to open another panel, use a bu

2条回答
  •  不知归路
    2021-02-20 05:00

    In versions of JQuery UI 1.10 or greater the .activate function has been deprecated in favour of using the 'option' method so an alternative approach using the previous answer and would be:

    $("#button").click(function(){
        var index = $("#accordion").accordion('option','active');
        var total = $("#accordion").children('div').length;
        index++;
    
        // include restart same as previous answer     
        if (index >= total) {
            index = 0;
        }
    
        $("#accordion").accordion("option", "active", index);
    
    }
    

提交回复
热议问题