william007
william007

Reputation: 18525

Clicking link with anchor # not go to top of the pages

I have a link as follows

<a href='#'>click to update the page</a>

What the link does it that it triggers a JavaScript code to update the contents of a div without posting back to the server. The problem is that when I click the link, it always go to the top to the page due to href='#'. Is it possible to avoid this movement?

Upvotes: 0

Views: 1637

Answers (3)

Code Lღver
Code Lღver

Reputation: 15603

You can avoid to post the link by following code:

<a href='javascript:void(0);'>click to update the page</a>

use it the page will not be refresh by this.

Upvotes: 0

Pouki
Pouki

Reputation: 1664

Try :

<a href='javascript:void(0)'>click to update the page</a>

Upvotes: 0

Antony
Antony

Reputation: 15106

Quick and dirty.

<a href='javascript:void(0)'>

You can also use CSS to simulate a hyperlink hand without using <a>.

cursor: pointer;

Upvotes: 5

Related Questions