link with href="#" scrolls page to top when used with jquery slidetoggle [duplicate] link with href="#" scrolls page to top when used with jquery slidetoggle [duplicate] jquery jquery

link with href="#" scrolls page to top when used with jquery slidetoggle [duplicate]


Several options:

  1. Put return false; at the bottom of your click handler and the href wont be followed.
  2. Change the href to javascript:void(0);
  3. Call preventDefault on the event in your handler:

    function( e ) {  e.preventDefault();  // your event handling code}


You need to add return false; to your click handler.
This will prevent the browser from executing the default action for the click.


Others have given you solutions. But to specifically answer your question, # refers to the current page. And since the interpretation of tags is to bring the top of the tag into view, clicking on a # tag scrolls you to the top of the current page.