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 3322382
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:10:31+00:00 2026-05-17T23:10:31+00:00

I am working on a site that has multiple sections, each with around 5-10

  • 0

I am working on a site that has multiple sections, each with around 5-10 projects within them. I am trying to create a next/previous navigation that will allow you to scroll through the projects within each section. This is the code I had for this:

  var prev_li     = $('.projects ul li.selected').prev('li'),
  prev_href   = $(prev_li).children().attr('href'),
  next_li     = $('.projects ul li.selected').next('li'),
  next_href   = $(next_li).children().attr('href');

$('#previous-project').click(function(e){
        if ($(prev_li).length) {
          window.location = prev_href;
          return false;
        } else {
          window.location = last_href;
          return false;
        }
  });

And then the same from the next project. My problem is that there are duplicate projects (some projects are in multiple sections). This means that multiple projects have the same URL and so some projects will get the class of “selected” when they really are not selected. This means that when you are on a project that is in multiple section and click the next or previous button, it will go to the previous project from the first instance of the project (even if that is in another section). I need some efficient way to specify the list of projects within each section and so it only rotates through those projects.

One idea I had was to add a class to each list of projects and do something like this:

  var traeng_prev_li     = $('.transportation-engineering.projects ul li.selected').prev('li'),
      traeng_prev_href   = $(traeng_prev_li).children().attr('href'),
      traeng_next_li     = $('.transportation-engineering.projects ul li.selected').next('li'),
      traeng_next_href   = $(traeng_next_li).children().attr('href');

// same variables for each section

  $('#previous-project').click(function(){
    if ($(traeng_prev_li).length) {
      window.location = traeng_prev_href;
      return false;
    } else if ($(struct_prev_li).length) {
      window.location = struct_prev_href;
      return false;
    } else if ($(civil_prev_li).length) {
      window.location = civil_prev_href;
      return false;
    } else if ($(archi_prev_li).length) {
      window.location = archi_prev_href;
      return false;
.... //all the way down through all the sections

The problem with this is a) it is terribly inefficient and b) I think even if you are not on that list, it still has a length and so the problem still persists?

  • 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-17T23:10:32+00:00Added an answer on May 17, 2026 at 11:10 pm

    add hashes at the end of the urls that specify the section

    like /projects/poplar_street_roundabou#transportation-facilities

    then you can use the location.hash to target the specific section when finding next/prev

    var prev_li = $('.projects.' + window.location.hash.substring(1) + ' ul li.selected').prev('li')
    

    kind of step by step explanation

    when the url has a #transportation-facilities (called hash) we can access it from javascript with the window.location.hash property.

    but it will return the # char as well, so we need to remove it by using the substring() method.

    Now in jquery we need to target the ul that is inside an element that has the projects class but also the transportation-facilities class. In CSS this is achieved by using the multiple class selector for example .class1.class2 will match elements that have both class1 and class2 assigned to them.

    so this line

    $('.projects.' + window.location.hash.substring(1) + ' ul li.selected').prev('li')
    

    translates to

    $('.projects.transportation-facilities ul li.selected').prev('li')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Django site that has multiple sections and subsections. I'd like
I am working on a ASP.NET MVC web site that has multiple submit buttons.
Im working on a site that currently has multiple H1 tags per page. What
I am working on a site that multiple projects will be using to enter
Working on a site that has multiple focus() events spread throughout maybe a dozen
Ok Im working on a site that has a sidebar and a main content
I'm working on a site that has a requirement to share session between a
I'm working on a site that has about 3,000-4,000 dynamically generated pages, and I'm
I'm working on a site that still has a lot of scripts in ColdFusion.
I am working on a medium size web site that has plenty of custom

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.