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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:27:24+00:00 2026-05-23T06:27:24+00:00

I have a button that grabs some data from the server using ajax, and

  • 0

I have a button that grabs some data from the server using ajax, and when it’s done, it it supposed to add a element to the DOM.

The element to add will be something like this

<div class="SomeClass">
  <div class="SomeOtherClass">
    <span class="Name">name from server</span>
    <span class="Manufacturer">manufacturer from server</span>
  </div>
  <span class="Weight">weight from server</span>
</div>'

In my jQuery function that gets the data back from the server, what is the best way to create this structure, put the data (name, manufacturer and weight) from the server in at the correct places, and put it into the DOM. I have got it working like this:

$("#ItemList").append('<div class="SomeClass"><div class="SomeOtherClass"><span class="Name">' + value.name + '</span><span class="Manufacturer">' + value.manufacturer + '</span></div> ' +
                       '<span class="Weight">' + value.weight + '</span></div>');

But this does not look very good, and it’s hard to see the proper structure.

What is the best way of doing this in a clean manner?

  • 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-23T06:27:25+00:00Added an answer on May 23, 2026 at 6:27 am

    If i needed multiple “version” of the structure I would go with adding something like

    <div class="SomeClass" id='SomeClassTemplate' style='display:none'>
       <div class="SomeOtherClass">
          <span class="Name">name from server</span>
          <span class="Manufacturer">manufacturer from server</span>
       </div>
       <span class="Weight">weight from server</span>
    </div>
    

    at the bottom of my html body, and then inside my the event handler where the element is to be added i would do

    var newDiv = $("#SomeClassTemplate").clone();
    newDiv.attr("id","whatever") 
    // remember this id should be different for each instance. or you can remove it
    .appendTo("whatever") // depends on where in DOM you want to insert it
    .find(".name").html("My name");
    
    newDiv.find('.manufacturer').html("my manufacturer);
    newDiv.show();
    

    The advantage i found with this approach is that this code can easily be modified by tweaking the selectors in case the structure changes.

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

Sidebar

Related Questions

I have a powerpoint pres that grabs some data from an excel sheet when
We have a button that saves asynchronously using AjaxToolKit/C#/.NET. I'm getting this in my
I have a page with a button that when I click, it retrieves data
I have a website that grabs a random entry from a database and displays
I have some jQuery that when you click the save button it triggers a
I'm using Flashbuilder for this. I have a button that changes the id of
I have a form that consists of two data grids and a button. Datagrid
I have a button that when clicked displays some information, can i manually trigger
I have a button that I would like to disable when the form submits
I have a Button that is looking at 2 comboboxes to make sure they

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.