When you have nested elements and they have the same event listeners, depending on how you add listeners, events will be fired in different order. See
this page My guess is showMenu() is getting called first and then immediately hideMenu() is getting called.