Detecting jquery-ui accordion open / close state

following code return you the active panel,

var active = $( ".selector" ).accordion( "option", "active" );

from the demo site, I noticed there's a ui-state-active class on opened section. So you can use jQuery.hasClass for your code...


The basic HTML structure of the accordion is:

<h3>
    <a>...</a>
</h3>

The way I have done it in the past is to assign a class to the tag like so:

<h3>
    <a class="my_accordion">...</a>
</h3>

jQuery UI assigns different classes to the tag based on its state.

if($('.my_accordion').parent('h3').hasClass('ui-state-active')) {
    // accordion is open
}
else {
    // accordion is closed
}