Determine currently opened Semantic UI accordion index

半世苍凉 提交于 2019-12-13 01:51:45

问题


Trying to figure out how to determine currently open part of Semantic UI accordion (http://semantic-ui.com/modules/accordion.html):

This works for jQuery UI Accordion, does not work for Semantic UI:

$("#accordion").accordion('option','active');

Also tried below code, but always returns "1":

    $('#selector').accordion({
        onChange: function() {  
            alert("selected" + $('#selector').index() );
        }
    });

回答1:


Inside the onChange callback, this returns selected content' container as a jQuery object. So you can use it with the index() method, filtered by content selector. Try with next, it works for me:

$('.ui.accordion').accordion({
    onChange: function () {
        alert(this.index(".content"));
        console.log(this.index(".content"));
    }
});

Working example: http://jsfiddle.net/n8o1ps0t/



来源:https://stackoverflow.com/questions/25573315/determine-currently-opened-semantic-ui-accordion-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!