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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:59:06+00:00 2026-05-16T17:59:06+00:00

So for example, I have a list and I need to extract the hrefs

  • 0

So for example, I have a list and I need to extract the hrefs from it:

<ul class="list1">
<li><a href="link1">Link1</a></li>
<li><a href="link2">Link2</a></li>
<li><a href="link3">Link3</a></li>
</ul>

BTW, this forums spam protection is not letting me put any more hyper links which is why the code above is semantically incorrect.

And apply those hrefs to the list below in order

<ul class="list2">
<li><a>Link1</a></li>
<li><a>Link2</a></li>
<li><a>Link3</a></li>
</ul>

It is to be dynamic (meaning as many hrefs in the first list as I want), so I’m not looking to use eq or nth, I’ve gotten this far by reading help in this forum, but am unclear on how to continue with applying the hrefs to the second list:

var hrefs = '';

$('ul#direction-fade-slider li a.url').each(function(idx, item) {  
  hrefs += item.href + '\n';  
});

Any help would be greatly appreciated! 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-16T17:59:07+00:00Added an answer on May 16, 2026 at 5:59 pm

    You can do it using a .each() loop like this:

    var anchors = $("ul.list2 a");
    $("ul.list1 a").each(function(i) {
       anchors.get(i).href = this.href;
    });
    

    All this is doing it getting the destination anchors (or you can reverse it…), looping through the <a> elements in order and setting the href on the corresponding one at the same index in the destination .list2.

    Alternatively, you could use .attr() like this:

    var source = $("ul.list1 a");
    $("ul.list2 a").attr('href', function(i) {
       return source.eq(i).attr('href');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an List<int> which contains 1,2,4,7,9 for example. I have a range from
For example I have such query: Query q = sess.createQuery(from Cat cat); List cats
I'm trying to extract the names from this list: new String: blood cz TheDeAtH
I have a list of million urls. I need to extract the TLD for
For example I have long list of buttons: <input type=button name=clickbutton onclick='dosomething(this)'> But instead
I need to extract all available parents for a file. For example, i have
Case example: I have a long list of items, and when I put my
Possible Duplicate: Java - Regex problem I have list of URLs of types: http://www.example.com/pk/etc
I have a list of objects (for the sake of example, let's say 5).
I have a List that contains items, for example: 1) https:\\10.12.23\\ 2) https:\\12.23.12.25\\ 3)

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.