You need to make a tab-control so that the tabs open with the slideDown effect.
At the beginning all forms are hidden, press the "Form 1" button, a block with the slideDown effect slideDown , when you click the "Form 2" button, another form opens, closing the previous one. If you click on the same button twice, then just open - close the form (like toggleClass).
The question is - when I open the first form, then when I open the second one it opens from the bottom (and I would like it to open from the top). it turns out if you open the second form first and then the first one, then it opens from the top, but if otherwise, the second form opens from the bottom
It turns out if you first open the first and then the second (and subsequent), then they open from the bottom, if in the opposite direction, then from above
css
.tab-collapse-first, .tab-collapse-second,.tab-collapse-three{ display: none; } HTML
<div class="col-lg-12 col-xl-12 col-md-12 col-12 p-0"> <div class="button-wrapper-main"> <a class="first-btn-tab btn-tab" data-target="first">Форма 1</a> <a class="second-btn-tab btn-tab" data-target="second">Форма 2</a> <a class="three-btn-tab btn-tab" data-target="three">Форма 3</a> </div> </div> <div class="col-lg-12 col-xl-12 col-md-12 col-12 p-0"> <div class="tab-collapse-first tab-collapse"> <p>ПЕРВАЯ ФОРМА ПЕРВАЯ ФОРМА ПЕРВАЯ ФОРМА ПЕРВАЯ ФОРМА ПЕРВАЯ ФОРМА ПЕРВАЯ ФОРМА ПЕРВАЯ ФОРМА ПЕРВАЯ ФОРМА ПЕРВАЯ ФОРМА ПЕРВАЯ ФОРМА ПЕРВАЯ ФОРМА ПЕРВАЯ ФОРМА ПЕРВАЯ ФОРМА</p> </div> <div class="tab-collapse-second tab-collapse"> <p>ВТОРАЯ ФОРМА ВТОРАЯ ФОРМА ВТОРАЯ ФОРМА ВТОРАЯ ФОРМА ВТОРАЯ ФОРМА ВТОРАЯ ФОРМА ВТОРАЯ ФОРМА ВТОРАЯ ФОРМА ВТОРАЯ ФОРМА ВТОРАЯ ФОРМА ВТОРАЯ ФОРМА ВТОРАЯ ФОРМА</p> </div> <div class="tab-collapse-three tab-collapse"> <p>Третья форма Третья форма Третья форма Третья форма Третья форма Третья форма Третья форма Третья форма Третья форма Третья форма Третья форма Третья форма Третья форма </p> </div> </div> js
$('.btn-tab').on('click',function(){ target = $(this).attr('data-target'); current_selector = '.tab-collapse-'+target; if ($(current_selector).hasClass('show-collapse')){ $(current_selector).removeClass('show-collapse'); $(current_selector).slideUp('fast'); } else{ hide_collapse(); $(current_selector).addClass('show-collapse'); $(current_selector).slideDown('fast'); } }) function hide_collapse(){ $('.tab-collapse').each(function(){ if ($(this).hasClass('show-collapse')){ $(this).removeClass('show-collapse'); $(this).slideUp('fast'); } }); } The function was written, since the number of tabs will grow in the future, so that it would be easier to track open tabs.