I'm having this code
$(".menu").on('click', function(e) {
e.preventDefault();
$(this).addClass("open").children("div").slideDown(200);
});
$(document).on('click', ".menu.open", function(e) {
e.preventDefault();
$(this).removeClass("open").children("div").slideUp(200);
});
when I click the .menu
the inner div slides down but it slides up again immediately and the open class is removed that's by only 1 click so how to fix this and make it work normal as a drop down menu for small screens opened by a click and closed by another click
You are assigning the class
open
immediately on click and then sliding down-which is causing the delegated callback to be called. You should assign the class at the end of the animation and make sure you are not calling the
open
menu again -