close a section of a accordion in jquery

Jorge picture Jorge · Jun 1, 2011 · Viewed 11.6k times · Source

It's a simple question, but i don't know how do it. I think there's a way to close all of the sections in the accordion attached to a event click, but i haven't found a method that will allow it to be done. I tried this:

$(document).ready(initialize);

$("#accordion").accordion("destroy");

$("#accordion").accordion({
    collapsible: true,
    active: false
});

function initialize() {

    $(".btnOk").click(function (e) {
    e.preventDefault();
    $("#accordion").accordion("active", false);
    }
}

Answer

Dusty picture Dusty · Jun 1, 2011

I think you're looking for the activate method instead of active method. I haven't tried it, but I think you should change:

$("#accordion").accordion("active", false);

to:

$("#accordion").accordion("activate", false);

Hope this helps.