/    Sign up×
Community /Pin to ProfileBookmark

Possible to stop page jumping when # link is used?

Hello,

When I use an <a href> link internally with #, the page jumps to the top. Is there any way to stop this?

Thanks

to post a comment
HTML

4 Comments(s)

Copy linkTweet thisAlerts:
@rtretheweyMar 15.2013 — If you use <a href="#"> and there's no onclick() function (and/or the user is running with JavaScript disabled), the browser will correctly consider the link to be pointing to the top of the current document. There's no way around that except to add an onclick() function or remove the 'href' attribute entirely.
Copy linkTweet thisAlerts:
@jedaisoulMar 16.2013 — Why would you use href="#" and not want it to jump to the top? That is what it does!!! Are you using anchors as the target of links, because they could be named. If so, that is obsolete. Use ID="target" attribute in any div etc...
Copy linkTweet thisAlerts:
@davidwhiteauthorMar 18.2013 — Why would you use href="#" and not want it to jump to the top? That is what it does!!! Are you using anchors as the target of links, because they could be named. If so, that is obsolete. Use ID="target" attribute in any div etc...[/QUOTE]

Yes I think that's what I'm doing. I'm a bit new to this.

I am using href="#" to link to somewhere on the same page, not another page.

So it's like:

<a href="#name1">My text</a> to click on

then

<div id="name1"> for the place where the link is.

I have DIVs with hidden content which only show when you go to them.

I just want to link internally to them on the same page without it making the page jump and scroll to the top which is annoying.

Thanks
Copy linkTweet thisAlerts:
@jedaisoulMar 19.2013 — Some possible reasons why this is happening:

a) The browser: which browser/version are you using?

b) The href and ID: Are you sure they match EXACTLY?

c) How are you making the hidden text appear/disappear?

Try disabling the code hiding/revealing the text and see if the page jumps to the top still. If not it's the code doing the hide/reveal which is causing it.
×

Success!

Help @davidwhite spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...