Benn
Benn

Reputation: 5023

Bootstrap 2 or Bootstrap 3 how to collapse open accordion

I am building own accordion markup by using bootstrap collapse

Does anyone know how to close the open accordion when you click on any other?

I tried with

        //bs2
        $('#top1_accordion').on('show','.collapse', function() {
            $('#top1_accordion').find('.collapse.in').collapse('hide');
        }); 
        //bs3
        $('#top1_accordion').on('show.bs.collapse','.collapse', function() {
            $('#top1_accordion').find('.collapse.in').collapse('hide');
        }); 

bootstrap 3 works on first click only http://jsfiddle.net/4WsFK/1/

I got it working on bootstrap 2

http://jsfiddle.net/MTKp7/26/

Any help is appreciated!

Upvotes: 0

Views: 351

Answers (1)

Matt Klinker
Matt Klinker

Reputation: 773

I believe the this fiddle should work. I only removed the class 'collapse' from your find statement. I'm not sure of all differences in 3.0, but they must've changed the markup slightly.

$('#top1_accordion').find('in').collapse('hide');

http://jsfiddle.net/9jZDE/1/

Upvotes: 1

Related Questions