简体   繁体   中英

Close all bootstrap accordions

I want to save my accordions as an image with HTML2CANVAS. For this i open up all accordions and everything's nice, but then they won't close later on. I digged around and found this great code:

function openAccordions(){
    $('.panel-collapse:not(".in")')
    .collapse('show'); 
}

function closeAccordions(){
    $('.panel-collapse.in')
    .collapse('hide'); 
}

By the looks of it and googling around this should work, although the function openAccordions() work but closeAccordions() does not (elements stay collapsed).

Any ideas how to work around or why this particular code might not work?

try check for visibility. Like so:

function openAccordions(){
    $('.panel-collapse').not(':visible')
    .collapse('show'); 
}

function closeAccordions(){
    $('.panel-collapse').is(':visible')
    .collapse('hide'); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM