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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:36:39+00:00 2026-06-09T10:36:39+00:00

I make a script. That get the href of the element. But i want

  • 0

I make a script. That get the href of the element. But i want only the last part of this url. I make this:

var newURL = $(".list-portfolio a").attr("href");
    pathArray = newURL.split( '/' ),
        secondLevelLocation = pathArray[0];

    var newPathname = "";
    for ( i = 3; i < pathArray.length; i++ ) {  
      newPathname += "/";
      newPathname += pathArray[i];
    }

this results in this /portfolio/ruimzicht.html Thats almost good. How can i remove the first /.

Do you have any tips to improve the code?

  • 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-06-09T10:36:41+00:00Added an answer on June 9, 2026 at 10:36 am

    Why not use an array function?

    var pathArray = ["portfolio", "ruimzicht.html"];
    
    // build a string by inserting a forward slash between all elements
    pathArray.join("/");
    
    // results in: portfolio/ruimzicht.html
    

    If you’re just interested in the last part anyway, you could shrink this into a one liner:

    url.split("/").pop(); // yields "ruimzicht.html"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a script that takes a URL to a file and
I want to make a script that can be used to send messages to
I want to make a script that starts a program and then sends it
I want to write a script that will get me straight to a python
I would like to make a script that outputs only the real time value
How can I make a script that tells me what the error is when
I need to make a script that will take files from a user and
I'm trying to make a script that will prompt the user and wait for
I'm trying to make a script that automatically starts uploading after the data has
I'm trying to make a script that will go into a directory and run

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.