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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:52:06+00:00 2026-06-13T05:52:06+00:00

Having real trouble with this one and I know it’s simple. Google isn’t helping

  • 0

Having real trouble with this one and I know it’s simple. Google isn’t helping too much because I’m not quite sure what to ask. So here’s the deal:

I’ve got a list of anchors and need to append two attributes from each of them to an array in a specific format. I can easily grab the attributes for each element, but I’m not sure how to append them to the array. Here’s what I’m looking for:

Goal Array Output

slides = [{
    img: 'img/aaron1.jpg',
    desc: '127'
}

HTML

<section id="photoBin">
    <ul>
        <li><a id="test" href="img/aaron1.jpg" title="Photo #127">127</a></li>
        <li><a href="img/aaron2.jpg" title="Photo #128">128</a></li>
        <li><a href="img/aaron3.jpg" title="Photo #129">129</a></li>
        <li><a href="img/aaron4.jpg" title="Photo #130">130</a></li>
        <li><a href="img/aaron5.jpg" title="Photo #131">131</a></li>
        <li><a href="img/aaron6.jpg" title="Photo #132">132</a></li>
    </ul>
</section>

JavaScript

var slides = [];

$('li a').each(function(){

    var el = $(this)
        img,
        desc;

        img = el.attr('href');
        desc = el.attr('title').split('Photo #');
});

Thanks for your help! Lets chalk this one up to easy reputation 🙂

  • 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-13T05:52:08+00:00Added an answer on June 13, 2026 at 5:52 am

    You’re missing the part where you add them to the array via push.

    Also, split gives you an array; if you’re only looking for the second piece of the split (the number), you need to access the second element of that array via the index accessor [1]:

    http://jsfiddle.net/H4wWX/1/

    var slides = [];
    
    $('li a').each(function(){
        var el = $(this);
    
        slides.push({
            img: el.attr('href'),
            desc: el.attr('title').split('Photo #')[1]
        });
    });
    

    You may also want to consider bullet-proofing this; if el.attr('title') is not a string or doesn’t contain "Photo #", the split/index accessor will throw an exception.

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

Sidebar

Related Questions

Been having real trouble with this one and wondered if someone may have found
I have been having some real trouble with this for a while. I am
I'm having a real trouble to get accents right, and I believe this may
Probably something really simple, but I'm having some real trouble with it. I have
This is probably not a very difficult question to answer. I'm having trouble with
I am having real trouble referencing a simple image in a jar file. I
I'm having a real nightmare parsing data from one database where much of the
I am having some real trouble with this, below is the code, I am
I'm having real trouble getting my head around this issue. As the title suggests,
I'm surprised that I'm having real trouble finding how to do this. It seems

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.