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

The Archive Base Latest Questions

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

I’ve got a list that looks like this: <li class = current_parent level-0> <a>

  • 0

I’ve got a list that looks like this:

<li class = "current_parent level-0">
  <a> Parent Link </a>
  <ul class= "children">
     <li class = "level-1">
           <a> Link to child </a>
     </li>

     <li class = "level-1 current_page_item">
          <a> Link to child </a>
     </li>

     <li class = "level-1">
           <a> Link to child </a>
     </li>

     </ul>
</li>

I also have some jQuery to look for the siblings of that “current page item” and get some info (The title and URL) from them. In the example above, where the “current page item” is flanked by two siblings on both sides, the code works great:

//Get URLs, run a length check against them. Execute functions are necessary. Pass the functions the relevant URL
        var nextURL= $(".current_page_item").next().find("a").attr("href"); //Get the HREF of the next page in list
        var previousURL= $(".current_page_item").prev().find("a").attr("href"); //Get the HREF of the previous page in list


        if(previousURL.length >= 1){    
            alert ("Setting prev URL!");
            setPrevPageLink(previousURL);
        }
        else if(previousURL == undefined){
            alert ("Hiding prev URL!");
            $('.previous_link').hide();
        }


        if (nextURL.length >= 1){
            alert ("Setting next URL!");
            setNextPageLink(nextURL);
        }
        else if(nextURL == undefined){
            alert ("Hiding Next URL!");
            $('.next_link > a').hide();
        }

       function setPrevPageLink(previousURL) {

           var prevTitle = $(".current_page_item").prev().find("a").attr("title"); //Get the title of previous page in list. WP provides.
           $(".previous_link > a").attr("href", previousURL); //Set the 'Previous Link' to the URL of the previous item in list.
           $(".previous_link > a").text(prevTitle); // Set the Title Text of the Link to the title of the previous Item in the List
           alert ("Previous URL is" + previousURL + "and it's title is " + prevTitle + "and it's length is " + previousURL.length); //Drop an alert for Debug
       }

       function setNextPageLink(nextURL){

            var nextTitle = $(".current_page_item").next().find("a").attr("title");
            $(".next_link > a").attr("href", nextURL);
            $(".next_link > a").text(nextTitle);
            alert ("Next URL is" + nextURL + "and the title is" + nextTitle + "and it's length is" + nextURL.length);
       }

However, if the “current page item” is at the START of a list (i.e., it has no “higher” sibling, just a “lower” one), this code never executes. Why? Nothing happens in it. If the “current page item” is at the END of a list, everything goes fine.

Also, Bonus Q: The “== undefined” never works. Why? What’s the isset equivalent in Javascript?

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

    It’s because previousURL will be undefined if there’s no link to get the href from, so you need to check for undefined before checking the .length of the property, like this:

        if(previousURL === undefined){  
            alert ("Hiding prev URL!");
            $('.previous_link').hide();
        }
        else if(previousURL.length >= 1){  
            alert ("Setting prev URL!");
            setPrevPageLink(previousURL);
        }
    

    Make sure to do the same for the nextURL. I think your confusion comes from a bad test, it does blow up if it’s at the end of the list as well, you can test it here.

    Here’s an updated/working version for all scenarios.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I know there's a lot of other questions out there that deal with this
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.