Detecting jquery-ui accordion open / close state

前端 未结 5 2133
眼角桃花
眼角桃花 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:31

    Although the Accordion control is a jquery UI component you don't have to use jquery to verify the control is in its expanded state. A simple check like this will do:

    /**
    * returns true if the elt is a header tag of an accordion control
    * that is in the active state (expanded)
    * @param {HTMLElement} elt - one of the header elements of the accordion div
    */
    function isActive(elt){
        elt.classList.contains('ui-state-active');
    }
    

    if you WANT to use jquery you can do this:

    $('query-string').hasClass('ui-state-active');
    

提交回复
热议问题