Tuesday, April 29, 2014

jquery close navigation submenu when click away

$(document).ready(function () {
    $(".navbar-sub-opener").click(function (evt) {
        //close submenu when click away - part 2
        evt.stopPropagation();
        //hide all submenus
        $(".navbar-sub").hide();
        //only open the one that's immediate inside the clicked parent menu item
        $(this).next($(".navbar-sub")).show();
    });

    //close submenu when click away - part 1
    $('html').click(function () {
        $(".navbar-sub").hide();
    });
});

No comments: