Dave
Dave

Reputation: 9167

How to close jQuery accordion before opening next one?

After opening an accordion item and then clicking on a new accordion item, I want it to first close the open one and then open the new one.

Here's my current code:

jQuery('.acclink').click(function () {
    jQuery("#accordion").accordion("activate", -1); // this closes anything open
    jQuery(jQuery(this).attr('href')).click(); // this is supposed to open the new one but doesn't. It WILL work when the above function is commented out.
    return false;
});

Here's my page: http://www.savedeth.com/objectivescenes/ What am I missing?

Upvotes: 0

Views: 1951

Answers (3)

Aniket
Aniket

Reputation: 379

I think you can use jqueryui's, accordion which does this by default.

Upvotes: 0

Shikha
Shikha

Reputation: 39

Try this

$(document).ready(function() { ("#accordion").accordion;});

Upvotes: 1

Federico
Federico

Reputation: 739

No need to type jQuery, $('#accordion').<method> is enough.

Are you sure that jQuery(jQuery(this).attr('href')) is selecting what you want? Print it using console.log(Query(jQuery(this).attr('href')))

I think accordion already does everything you need by itself.

Probably $('#accordion').accordion() is the simplest solution.

Upvotes: 0

Related Questions