#4673 closed enhancement (fixed)
Method to find current active item
Reported by: | wichert | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | ui.accordion | Version: | 1.7.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
It would be nice to have a method to find out what the index number of current active item is. An example use for this is to programatically activate the next or previous item.
Change History (5)
comment:1 follow-up: 2 Changed 14 years ago by
comment:2 Changed 14 years ago by
Replying to wichert:
As a workaround you can use this bit of code:
var accordion = $(".accordion"); var items = $.map(accordion.find("dt"), function(a) { return $(a).hasClass("ui-state-active"); }); var active = $.inArray(true, items);
If you place this code in the following way, it always produces -1:
$("#accordion").accordion({
header: "h3", fillSpace: true, change: function(event, ui) {
var accordion = $(".accordion"); var items = $.map(accordion.find("dt"),
function(a) { return $(a).hasClass("ui-state-active"); });
var active = $.inArray(true, items); alert(active); }
});
The JQuery should not only make "active" work, but the documentation should be clearer about what properties are set up for
ui.newHeader jQuery object, activated header
ui.oldHeader jQuery object, previous header
ui.newContent jQuery object, activated content
ui.oldContent jQuery object, previous content
comment:3 Changed 14 years ago by
In fact the very simplest workround is to add a unique class to each header with click( fn ) (or hover event) attached to it. That will enable a value to be assigned to a variable or initiate an action.
As a workaround you can use this bit of code: