When I click the “#” links, my browser automatically navigate to the top of the page

How to stop this?

  1. Uses “#_” instead of “#”, on some browser it just worked same as “_top”
  2. Use JavaScript to prevent this happening

Code snippet

For example if you have a link similar as below:

<a href=”#” class=”noAction”>Click me</a>

You can add the follow function to prevent the navigation:

$(“a.noAction”).click(function (e) {
//You can add additional function here for execution
e.preventDefault();
});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s