www.webdeveloper.com
Results 1 to 5 of 5

Thread: Possible to stop page jumping when # link is used?

  1. #1
    Join Date
    Nov 2011
    Posts
    16

    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

  2. #2
    Join Date
    Mar 2011
    Posts
    1,145
    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.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Mar 2012
    Posts
    1,647
    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...

  4. #4
    Join Date
    Nov 2011
    Posts
    16
    Quote Originally Posted by jedaisoul View Post
    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...
    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

  5. #5
    Join Date
    Mar 2012
    Posts
    1,647
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles