Opened 14 years ago

Closed 14 years ago

Last modified 10 years ago

#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 Changed 14 years ago by 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);

comment:2 in reply to:  1 Changed 14 years ago by plane007

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 plane007

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.

comment:4 Changed 14 years ago by rdworth

Resolution: fixed
Status: newclosed

Fixed in r3044

comment:5 Changed 10 years ago by Scott González

Milestone: TBD

Milestone TBD deleted

Note: See TracTickets for help on using tickets.