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:


Prabhu Balakrishnan

Mr. Balakrishnan is a leading expert in Global citizenship and residency programs for high net worth immigrant investor clients. He is also entrepreneur with background in Computer science engineering. His other interests are Linux servers, Machine learning, Parallel computing, Computer vision, Wordpress, etc. He is born in India currently living in Budapest, Hungary.

  • 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.

  • Charlotte Coleman

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

  • Ricardo Zea

    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!

  • Kris

    You can also do this to solve that problem…

  • Rathinam

    Thank you! It helps me.

  • Ali Reza salimzadeh

    Thank you!
    It very helps me.

  • Mark

    I found that click me

  • Mark

    I found that click me works

  • Mark

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

  • Bouncer

    Problem solved, cheers

  • mmorpg

    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

  • Idan Rubin

    Thank you. Super useful.

  • dani

    Thank you it was very simple and helpful

  • Mayank

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