javascript - Bootstrap collapse - opening multiple accordions at the same time -
i've got point accordions open @ same time - see http://www.bootply.com/go4t29ryyf
when click on "tab1" "tab1s" open, when click on "tab2" "tab2s" open - great! cant open "tab1s & tab2s" @ same time, works when close 1 of tabs first before opening another. issue js cant work out.
$(function () { var $active = true; $('.panel-title > a').click(function (e) { e.preventdefault(); }); $('.number1-collapse').on('click', function () { if (!$active) { $active = true; $('.panel-title > a').attr('data-toggle', 'collapse'); $('.number1').collapse('hide'); } else { $active = false; $('.number1').collapse('show'); $('.panel-title > a').attr('data-toggle', ''); } }); $('.number2-collapse').on('click', function () { if (!$active) { $active = true; $('.panel-title > a').attr('data-toggle', 'collapse'); $('.number2').collapse('hide'); } else { $active = false; $('.number2').collapse('show'); $('.panel-title > a').attr('data-toggle', ''); } }); });
i've tidied code , changed using toggle
method instead of having various flags. problem sharing active flag between them. here improved code , bootply:
$(function () { $('.panel-title > a').click(function (e) { e.preventdefault(); }); $('.number1-collapse').on('click', function () { $('.number1').collapse('toggle'); }); $('.number2-collapse').on('click', function () { $('.number2').collapse('toggle'); }); });
Comments
Post a Comment