Reputation: 41
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() );
}
});
Upvotes: 1
Views: 2666
Reputation: 1
This is my function and works!!
window.AcordionIndex = async (div) => {
var index = 0;
for (var i = 0; i < document.getElementById(div.replace("#", "")).children.length; i++) {
var clase = document.getElementById(div.replace("#", "")).children[i].className;
if (clase.indexOf('title') != -1) {
if (clase.indexOf('title active') != -1) {
break;
}
index++;
}
}
return index;
}
Upvotes: 0
Reputation: 181
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/
Upvotes: 5