Fix-> JQuery onclick browser jumps to top of page!

JQuery onclick jumps to top of page

i had an issue with jquery code where i have a html link doing specific tasks for onclick event. Since the appear on bottom of my page, when i click on the link the browser jumps to top of the page every time i click.

<a href="#" onclick="dofunct()">click me</a>

This is really very frustrating as everytime i click a link, the browser jumps to top of page. After a long search, i fixed the problem by replacing # with javascript void function.

<a href="javascript:void(0);" onclick="dofunc()">click me</a>

It neatly solved my jump problem!

Similar Posts:


Balakrishnan Prabhu

Mr. Balakrishnan Prabhu is the founder of Corpocrat magazine. He is also the founder of Best Citizenships (BC), assisting wealthy individuals with with global citizenship and residency programs in Europe. His other interests are Linux, Machine learning, Wordpress, etc. You can contact him here

  • Peet

    Thank you! It helps me. 😉

  • Dave H

    Here is another solution:

    click me

    Returning false prevents the default action of the item you clicked on. I found your solution and this one while trying to solve the same problem. I like this better because you won’t have the ‘javascript:void(0)’ showing up in the bottom corner of your browser when you hover over the link.

  • Thanks, that post has saves me a lot of time debugging!

  • I while back I read that using ‘javascript:void(0);’ was not a best practice.

    Instead you can fix this problem by adding ‘return false;’ to your code, which is a more scalable way of fixing this problem.


    $(‘#container’).click(function () {
    return false;

    More info in this other post:

  • Dan McKenzie

    Thank you both – I went with “return false;”, but each option would suffice for my need. Very easy to find solution in Google.

  • Hungary

    Thank you :)) It’s good nice.

  • Mohio


  • crossan

    Clear and concise solution, many thanks!

  • You can also do this to solve that problem…

  • Thank you! It helps me.

  • Ali Reza salimzadeh

    Thank you!
    It very helps me.

  • I found that click me

  • I found that click me works

  • I found that <ahref=”#linktobottom”></a>

  • Problem solved, cheers

  • Worked perfectly, thanks a lot!

  • Kumar

    javascript:void(0) worked perfectly in all the cases even though it is not a best pratice. How ever return false will work if you are not returning anything in your function.
    In my case my function is returning a value so had to use javascript:void(0).
    Thanks for the good trick.

  • oraclemind

    You saved my life:D

  • Thank you. Super useful.

  • dani

    Thank you it was very simple and helpful

  • wow brilliant nice work i really appreciate this. keep it up.