ThemesCreator
ThemesCreator

Reputation: 1759

Jquery toggle only childens

I have this jquery code to toggle a submenu on click.

jQuery(document).ready(function($){
    $(".widget .menu-item-has-children").click(function () {
        $(".widget .menu-item-has-children > .sub-menu").toggle();
    });
});

But this display all .sub-menu, not only clicked link children. How can i put "only do this to children" with jquery?

Upvotes: 0

Views: 33

Answers (1)

Vitalii Petrychuk
Vitalii Petrychuk

Reputation: 14225

jQuery(document).ready(function($){
    $('.widget .menu-item-has-children').click(function () {
        // `this` refers to the current `.widget .menu-item-has-children`
        $(this).children('.sub-menu').toggle();
    });
});

Upvotes: 2

Related Questions