Javascript – Creating a null hyperlink

csshtmljavascript

I want to create a hyperlink that does not link to any page. When clicked it executes a javascript function i have defined.
So, i created a link as follows:

<a onclick="fun()"> SomeText </a>

But, the mouse pointer does not change to the hand symbol when we hover a mouse over the link.

So, i changed the link to

<a href="#" onclick="fun()"> SomeText </a>

So,now i get the hand symbol but now the location in the address bar changes to <url>/# whenever, i click on the link.

Is there a way to create a hyperlink not linking to any location, but the mouse pointer should change to the hand symbol on mouse hover over it ?

Thank You.

Best Answer

Return false from onclick event:

<a href="#" onclick="fun(); return false;"> SomeText </a>