L
L
luckyjenro02021-06-10 21:49:35
JavaScript
luckyjenro0, 2021-06-10 21:49:35

How to make multiple tabs out of this?

There is a code for tabs:

function openTab(evt, servName) {
    // Объявить все переменные
    var i, tabcontent, tablinks;

    // Получить все элементы с помощью class="tabcontent" и спрятать их
    tabcontent = document.getElementsByClassName("tab");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }

    // Получить все элементы с помощью class="tablinks" и удалить class "active"
    tablinks = document.getElementsByClassName("all_tab_link");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }

    // Показать текущую вкладку и добавить "active" класс для кнопки, которая открыла вкладку
    document.getElementById(servName).style.display = "block";
    evt.currentTarget.className += " active";
}

But if you set several tabs with this function, then the class will leave one, in general, I think you understood from the code. It is necessary to do so that it would be possible to create several, probably the data attribute should be used.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question