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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:48:53+00:00 2026-06-17T12:48:53+00:00

Im trying to create an array of object from ul li tags using jQuery

  • 0

Im trying to create an array of object from ul li tags using jQuery. Unfortunately I’m not able to do that. I’m pasting my code bellow.

var photos = [];
$( "#sliderContent li" ).each(function() {

  var title = $(this).find(".title").html();
  var image = $(this).find(".image".html());
  var url = $(this).find(".url").html();
  var firstline = $(this).find(".firstline").html();
  var secondline = $(this).find(".secondline").html();

  var slide = new Object();
  slide.title = title;
  slide.image = image;
  slide.url = url;
  slide.firstline = firstline;
  slide.secondline = secondline;
  photos.push(slide);
});

My HTML list ul li

<ul id="sliderContent" >
    <li>
        <div class="title">Stairs 1</div>
        <div class="image">vacation.jpg 1</div>
        <div class="url"># 1</div>
        <div class="firstline">Amazing Apartment for Rent in JBR 1</div>
        <div class="secondline">
            <div class='row'>
                    <div class='col1'>ABD 1</div>
                    <div class='col2'>EFG 1</div>
            </div>
            <div class='row'>
                <div class='col1'>ABD 1</div>
                <div class='col2'>EFG 1</div>
           </div><div class='row'>
            <a class='view' href='#'></a>
            <a class='arrange' href='#'></a>
           </div>
       </div>
    </li>
</ul>

This is what i want to create.

var photos = [ {
    "title" : "Stairs",
    "image" : "vacation.jpg",
    "url" : "",
    "firstline" : "Amazing Apartment for Rent in JBR",
    "secondline" : "lorem ipsum"
}, {
    "title" : "Office Appartments",
    "image" : "work.jpg",
    "url" : "",
    "firstline" : "Amazing Apartment for Rent in JBR",
    "secondline" : "work?"
}];

Please tell me where did go wrong, and also how to view the content of the array photos to check the result.

Any help would be appreciated.

  • 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-17T12:48:54+00:00Added an answer on June 17, 2026 at 12:48 pm

    while we’re at it, in response to gurvinder372’s answer, you could also create the object like this:

    var slide = {
        title: title,
        image: image,
        url: url,
        firstline: firstline,
        secondline: secondline
    };
    

    instead of you original version:

      var slide = new Object();
      slide.title = title;
      slide.image = image;
      slide.url = url;
      slide.firstline = firstline;
      slide.secondline = secondline;
    

    EDIT:
    now, that i took some more time… You could in this case use the jQuery.map function like this:

    var photos = $('#sliderContent li').map(function(index, liItem) {
        var $liItem = $(liItem);
    
        return {
            title: $liItem.find('.title').html(),
            image: $liItem.find('.image').html(),
            url: $liItem.find('.url').html(),
            firstline: $liItem.find('.firstline').html(),
            secondline: $liItem.find('.secondline').html()
        };
    });
    

    Remember to call this code only when the dom is ready (thus the list sliderContent exists). if you dont know the jQuery.map function, check out its doc: http://api.jquery.com/map/

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

Sidebar

Related Questions

I'm trying to create a json object from MySQL results, but not getting the
I am trying to create an array in my JavaScript object that contains objects
I'm trying to create an array from selected table rows so I can push
I am trying to create an array or list that could handle in theory,
I'm trying to create an array of strings that can be randomized and limited
I am trying to create a md5 string from the byte array of an
I'm trying to create an object array and it works just fine if I
I would like to create a new System.Windows.Xps.Packaging.XpsDocument object from byte array, as I
I'm trying to create associative array of objects from row result set with member
I'm trying to create a query that pulls information about sellers from my database,

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.