In this article i will try to explain how can we use javascript to jump to different anchor within a page.
Anchor HTML Code
[sourcecode language=”html”]
[/sourcecode]
Anchor Link
[sourcecode language=”html”]
[/sourcecode]
Example: Test HTML Code
Javascript function to jump to the anchor
[sourcecode language=”jscript”]
function goToAnchor(nameAnchor){
window.location.hash=nameAnchor;
}
[/sourcecode]
How to call javascript function to jump to anchor
[sourcecode language=”html”]Test Javascript Code
[/sourcecode]
Example: Test Javascript Code
Copyright © 2024 All rights reserved.
17th January 2009
Very useful!! Thanks
17th January 2009
i still don’t understand… but thanks i will try it again
17th January 2009
Thanks for this – it was part of the answer to a problem that had stumped me for some time.
17th January 2009
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
??
17th January 2009
Great code! but it seems to that only work for tag,not support tags.
17th January 2009
I tried your code, and, sadly, it failed for me. I was never able to jump to the anchor tag; it constantly went to the top of the page even though I have used a href=”window.location.hash=’loc'”