Search code examples
jquerypreventdefaultunbind

preventDefault to not affect its children


I have the following to prevent a click event and slideToggle a sub navigation, the problem is it prevents the child links (in it's sub navigation)from working. How do I either target the parent without effecting the children or unbind the preventDefault?

 $('#sidr-main .submenu-button a').click(function(e) {
    e.preventDefault();
    $(this).next().slideToggle();
});

Solution

  • Use the ">" child selector, to select only first-level descendants

    Your selector should be like this:

    $('#sidr-main .submenu-button > a')