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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:27:15+00:00 2026-05-28T17:27:15+00:00

I need to create multiple divs like below based on how many objects are

  • 0

I need to create multiple divs like below based on how many objects are in my collection

  <div class="container">
    <a href="#">title test</a>
    <div class="video">
    video test
    </div>
    </div>

I want to use jquery to acheive this.

for(i =0 ;i < list.size; i++){

$("#wrapper").append(createDiv(list[i]));

}

function createDiv(object){

 return <div class="container">
    <a href="object.link">object.title</a>
    <div class="video">
    object.video
    </div>
    </div>;
}

I feel this way to too hard coded as I may need to reconstruct the container class. For example I may want to put in another div tag or more links. I’m wondering if there is an alternative way to do this that would allow flexibility in my code. Instead of createDiv return one large string, should I be using query functions such as createElement?

Thanks for any advice 🙂

  • 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-28T17:27:16+00:00Added an answer on May 28, 2026 at 5:27 pm

    The best way to handle this type of problem is with a templating library. Templates allow you to define your HTML markup as strings with tokens in them.

    Then you can apply the template to a list of items, and it will replace the tokens with the matching properties from each item. This cleans up your code by eliminating the need to loop through the list.

    There are several popular templating libraries:

    • Mustache
    • jQuery Templates (this is deprecated but still used by a lot of people)
    • Underscore.js

    Here’s a quick example of how you might use jQuery templating on a list of items:

    var gridTemplate = '<div class="my-item">' +
                           '<div class="my-list-item-value">${ItemName}</div>' +
                           '<a href="#">$[DeleteLink]</a>' +
                       '</div>';
    $.templates("gridTemplate", gridTemplate);
    

    Underscore.js allows you to define your HTML in an actual .html document, which keeps your JavaScript files cleaner. Then you are free to change the HTML template any way you like without affecting your JavaScript as long as you keep the tokens in your HTML file.

    Here’s a good article about templating with Underscore.js.

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

Sidebar

Related Questions

so I have multiple divs of the same class below each other. I now
Background: I have a project where i need to create multiple objects that consume
Why do I need to create Multiple SSPs in MOSS? My manager (sharepoint administrator)
I'm new to GUI programming, but need to create a multiple window GUI. Does
I`v come across a need where I want to create multiple list items from
I need to create a batch file which starts multiple console applications in a
I need to create an XmlDocument with a root element containing multiple namespaces. Am
i need create an email list sending to many emails. what is best solution
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
This should be simple. I have ajax returning string, with multiple divs. I need

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.