Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable default behavior of links

I have a list of menus:

<ul>
    <li><a href="#about" id="about">ՄԵՐ ՄԱՍԻՆ</a></li>
    <li><a href="#products" id="products" >ԱՐՏԱԴՐԱՆՔ</a></li>
    <li><a href="#farm" id="farm" >ՏՆՏԵՍՈՒԹՅՈՒՆ</a></li>
    <li><a href="#gallery" id="gallery" >ՆԿԱՐՆԵՐ</a></li>
    <li><a href="#contacts" id="contacts">ՀԵՏԱԴԱՐՁ ԿԱՊ</a></li>
</ul>

and I use the address plugin to have back/forward along ajax, but I have a little bug that I'm not able to fix.

When I click on the menu, if the page has scrolling, it moves the page until the menu appears in the top of page, but I don't need it do that.

Is there a method to disable this behavior?

Thanks a lot.

like image 602
Simon Avatar asked Jul 05 '10 17:07

Simon


2 Answers

Create or modify the click() handlers for the links to use the preventDefault() method.

For example:

$("a").click 
(
    function (evt)
    {
        //YOUR CODE HERE

        evt.preventDefault(); 
        return false;  
    } 
);
like image 120
Brock Adams Avatar answered Sep 27 '22 16:09

Brock Adams


try adding the following to your links:

onclick="return false;"

Since you are probably adding an event handler to this link for the click event. Just add the return false to the end of it rather than directly on the HTML tag.

like image 42
spinon Avatar answered Sep 27 '22 17:09

spinon