Detecting jquery-ui accordion open / close state

前端 未结 5 2135
眼角桃花
眼角桃花 2021-01-04 19:47

How do I conditionally handle when an accordion section is open. What I am asking is this (in pseudo code):

if (this-accordion-section-open){
   do something         


        
5条回答
  •  不知归路
    2021-01-04 20:21

    The basic HTML structure of the accordion is:

    ...

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

    ...

    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
    }
    

提交回复
热议问题