Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6006927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:36:33+00:00 2026-05-23T01:36:33+00:00

I´m pretty profane in javascript. I need a previous and next link that will

  • 0

I´m pretty profane in javascript.

I need a previous and next link that will just go to the previous or next #anchor.

All the anchors are divs with the same ID

This is what I have managed to do:

<script type="text/javascript">
$(document).ready(function() {

// Go to the next link
function goToNext() {

        window.location.href = .next('#display');
    }
}

// Go to the previous link
function goToPrev() {

        window.location.href = .prev('#display');
    }
}

</script>

then

<a href="javascript:goToNext()">next</a>
        <a href="javascript:goToPrev()" >Prev</a>

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:36:34+00:00Added an answer on May 23, 2026 at 1:36 am

    It seems that you’re using jQuery.

    You can make your ID’s to end with a number:

    <div id="display_0">zero</div>
    <div id="display_1">one</div>
    <div id="display_2">two</div>
    <div id="display_3">three</div>
    <div id="display_4">four</div>
    <div id="display_5">five</div>
    
    
    <a href="#" id="prev">Prev</a>
    <a href="#" id="next">Next</a>
    

    Then bind functions to your next and prev links that increment/decrement an index, and set the location.hash to the ID plus the index.

    $(document).ready(function() {
    
           // index to reference the next/prev display
        var i = 0;
           // get the total number of display sections
           //    where the ID starts with "display_"
        var len = $('div[id^="display_"]').length;
    
    
           // for next, increment the index, or reset to 0, and concatenate 
           //    it to "display_" and set it as the hash
        $('#next').click(function() {
            i = ++i % len;
            window.location.hash = "display_" + i;
            return false;
        });
    
    
           // for prev, if the index is 0, set it to the total length, then decrement
           //    it, concatenate it to "display_" and set it as the hash
        $('#prev').click(function() {
            if (!i) i = len;
            --i;
            window.location.hash = "display_" + i;
            return false;
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pretty much every other editor that isn't a vi descendant (vim, cream, vi-emu) seems
Pretty much what the title says really. We have some code that is .NET
Pretty simple scenario. I have a web service that receives a byte array that
Pretty all in question... I'm looking for batch script, code or library which allows
Pretty straightforward stuff, here -- I'm just not good enough with mysql to understand
Pretty straight forward. MSDN states that you can use ref, but not out for
Pretty much all the apps I use on a regular basis implement this 'seemly
Pretty much, what the title says. I need to make the GWT DatePicker component
Pretty simple question this time around. I have an application that communicates with another
Pretty much exactly as it sounds. I have buttons in a Wx.Frame that are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.