Reputation: 1
I've searched for the answer on this forum, but haven't been able to find it. Here is my question:
I want disable the possibility to open the first and the second pane of my accordion, and allow it to open only when if want. It's like to make some panes disabled and some enabled.
I've searched with this code :
$( "#accordion" ).bind( "accordionchangestart", function(event, ui) {
var active = $(this).accordion( "option", "active" );
if(active == 0)||(active == 1)){
preventDefault();
}
});
It works only for the second pane ( == 1) because when the state is closed, it's considered as false, and false == 0 for jquery.
I've tried searching if the selected pane is the first with the ui-state-active class, but this is too late, when the class appears, the pane is opened, and that's what i want to prevent.
Any idea ?
Thanks
Upvotes: 0
Views: 5762
Reputation: 1263
If I want to take action only when expanding:
var active = $(this.container).accordion('option', 'active');
if (!active && $.type(active) === 'boolean') {
//No action
return;
}
//Loading some data inside accordion content
Upvotes: 0
Reputation: 7464
If you are using jQuery UI's Accordion than what you should do is use the changestart event to check which one is clicked and do whatever you want to do.
Use this to check the current state:
$( "#accordion" ).accordion({changestart: function(event, ui) {
alert(ui.newHeader[0].textContent);
}});
Yo can also change the current option like this:
$("#accordion").accordion("activate", 3);
You can find events documentation here: http://jqueryui.com/demos/accordion/#events
And here is the activate method documentation: http://jqueryui.com/demos/accordion/#method-activate
Upvotes: 0