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

  • SEARCH
  • Home
  • 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 6638413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:25:58+00:00 2026-05-25T23:25:58+00:00

I am trying to create dynamic next and previous buttons with javascript. I am

  • 0

I am trying to create dynamic next and previous buttons with javascript. I am stuck at the point of trying to create a variable that describes the current page I am on, relative to a ul tree.

I have looked at

    window.location;

But after returning the full url, I am stuck at striping this string down to just the x.html and then finding this in the li links.

After finding an li link in my ul tree I can generate the next and previous links using children as in this fiddle: http://jsfiddle.net/JyfS2/

Example code – If I am on page b, find this page, and make the PREV link link to a.html, and the NEXT to c.html

<ul>
    <li id="1"><a href="a.html">a</a></li>
    <li id="2"><a href="b.html/">b</a></li>
    <li id="3"><a href="c.html">c</a></li>
     </ul>
<div>
<a id="next" href="">next</a>
<a id="prev" href="">prev</a>
</div>

Some JS I have been using – So I would want to replace $(‘li#2’) with a variable that describes the current page:

    <script>
        var next_url = $('li#2').next()[0].firstChild.href;
        var prev_url = $('li#2').prev()[0].firstChild.href;
        var loc = window.location;
        alert(loc);
        document.getElementById('next').href = next_url;
        document.getElementById('prev').href = prev_url;

</script>
  • 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-25T23:25:59+00:00Added an answer on May 25, 2026 at 11:25 pm

    This will find the page from a url:

    var url = 'http://www.test.com/index.html'
    
    var split = url.split('/');
    var page = split[split.length-1];
    
    alert(page);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So here is the problem: I am trying to create dynamic buttons that have
I'm trying to create a dynamic popup window that is able to be re-sized.
I am trying to create a dynamic hyperlink that depends on a value passed
I am trying to create a dynamic bar in HTML using javascript. I have
I am trying to create dynamic predicate so that it can be used against
I'm trying to create a dynamic QSlider that accepts a QVector of integer values
I'm trying to create Dynamic SVG graphics, it is my understanding that the only
I am trying to create two dynamic dates in html/javascript/jquery. I want the dates
I'm trying to create a dynamic select box in JavaScript with a range of
I am trying to create dynamic menus from the database using the following example

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.