In this article i will try to explain how can we use javascript to jump to different anchor within a page.

Anchor HTML Code

<a name="mystory"></a>

Anchor Link

<a href="#mystory">Test HTML Code</a>

Example: Test HTML Code

Javascript function to jump to the anchor

function goToAnchor(nameAnchor){
     window.location.hash=nameAnchor;
}

How to call javascript function to jump to anchor

<a href="javascript:goToAnchor('mystory')">Test Javascript Code</a>

Example: Test Javascript Code


Anchor is here –> <–



Tags: , , , , , ,

4 Comments »

  1. Very useful!! Thanks

    Comment by Filo — February 17, 2009 @ 16:46

  2. i still don’t understand… but thanks i will try it again

    Comment by niko — October 27, 2009 @ 09:55

  3. Thanks for this – it was part of the answer to a problem that had stumped me for some time.

    Comment by nick — October 29, 2009 @ 21:59

  4. How can I do this on a page with referrers?
    e.g. URL is admin.php?date=xxx&title=yyy …
    then I want it to jump to a named anchor

    ??

    Comment by Terry — May 14, 2010 @ 14:04

RSS feed for comments on this post. TrackBack URL

Leave a comment