Tibor Ambrus Tibor Ambrus - 2 months ago 22
HTML Question

Mobile Menu button takes top of the page

I have a wordpress site and i used a template to do it. So when i'm on mobile it has a mobile menu i managed to make it fixed to stay at the top when i scroll down, but the problem is. When i'm on a certain place at the site and i wanna open the menu with the "three line" icon it's opening the menu but takes me to the top of the page as well. And when i wanna close the menu with the X button it takes me to the top of the page as well, so basically the menu is unusable. I know it's a Jquery problem, but i can't find which file contain the codes for it and even how to fix it.

My website is: www.autoberles-szombathely.hu

So i wanna make the open menu button and close menu button to only open and close the menu and don't take me to the top of the page.

Answer

you can use:

$(selector).click(function(event) {
    event.preventDefault();
    //other stuff you might want to do on event
});

For the record you should not remove the href entirely, it should always exist to prevent unexpected behavior. If you don't want the href to be be acted on then just use that preventDefault() method, easy and keeps everything running smoothly.