javascript onclick event fired page jumps to top of page

Posted on March 12, 2010. Filed under: jQuery | Tags: , |

I had arrised one issue with javascript event calling code where I had 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 focus jumps to top of the page every time , I clicked.

I had write , where this proble produced,

<a href="#" onclick="dofunct()">click me</a>

This is really very frustrating as everytime I click on that link, the browser jumps to top of page. After a long search, I got solution for problem by simple replacing # with JavaScript void function.

<a href=”javascript:void(0);” onclick=”dofunc()”>click me</a>

It neatly solved my jump problem!

<pre lang=”ruby”>
Advertisements

Make a Comment

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

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: