When I want to use one button to toggle all accordion-elements and some of them are already open, the toggle functionality behaves extremely strange.
If I implement this code:
$('.corearea-wrapper .corearea-link').click(function(e) {
e.preventDefault();
mywrapper = $('.corearea-wrapper #' + $(this).parent().children('.row.fixedcol').attr('id'));
if(mywrapper.hasClass('allopen')) {
mywrapper.find('.collapse').collapse('hide');
mywrapper.find('article').removeClass('active');
mywrapper.removeClass('allopen');
} else {
mywrapper.find('.collapse').collapse('show');
mywrapper.find('article').addClass('active');
mywrapper.addClass('allopen');
}
});
My expected result is: first click, close all elements, that are open, second click open all elements, third click close all, etc.
What happens instead: first click, opened elements get closed, BUT closed elements get opened, second click opened elements get closed (all elements closed), third click, all elements open, fourth click, all elements open, etc.
See demo here: