S
S
Stanislav2021-08-31 12:36:58
JavaScript
Stanislav, 2021-08-31 12:36:58

Why jQuery layered menu jumps?

Help, please, to understand.
Created a multi-level accordion menu, but it does not work correctly (the submenu jumps).
I can't figure out what's wrong.

<ul class="i01 level_1 accordion">
        <li class="nav_btn"><a>1111111111111</a></li>
        <ul class="i01 level_2">
            <li class="nav_btn"><a>2222222222222</a></li>
            <ul class="i01 level_3">
                <li class="nav_btn"><a>3333333333333333</a></li>
                <ul class="i01 level_4">
                    <li class="nav_btn"><a>4444444444444444</a></li>
                    <li class="nav_btn"><a>4444444444444444</a></li>
                    <li class="nav_btn"><a>4444444444444444</a></li>
                </ul>
            </ul>
        </ul>
    </ul>


$(function() {
    $('.i01.level_1 li').click(function() {
        $(this).next('ul').slideToggle().siblings('ul.level_2').slideUp();
    });
    $('.i01.level_2 li').click(function() {
        $(this).next('ul').slideToggle().siblings('ul.level_3').slideUp();
    });
    $('.i01.level_3 li').click(function() {
        $(this).next('ul').slideToggle().siblings('ul.level_4').slideUp();
    });
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
v3shin, 2021-08-31
@zalman2

$('.i01.level_1 li')already hangs a handler on all nested menu items. So when you click on the second level of the menu, handlers $('.i01.level_1 li')and $('.i01.level_2 li')and $(this).next('ul').slideToggle()work twice.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question