S
S
sergeymaverick2019-04-02 20:27:33
css
sergeymaverick, 2019-04-02 20:27:33

How to remove the class if neighboring li with class active?

There is a layout. The .active .first .last classes add CMS MODX. You need to do this with jq so that after the .active class is added to all the other li, the .active class disappears from the first li.active.first, and when all li do not have the .active class, then the first one has it. All this is now displayed through pdoMenu and he himself adds active classes depending on the page.
5ca39b51d423a078404422.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mesuti, 2019-04-02
@Mesuti

li are links to other pages ?
besides active something else is added? e.g. first. To understand which of the li really should be active
Without a sandbox, at first glance, this solution:

$('li').click(
        function () {

// Поиск active по списку и удаление
            document.querySelectorAll('li .active').forEach(n => n.classList.remove('active'));

// Присвоение active по кликнутому li
            $(this).addClass('active');
        }
    );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question