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

  • SEARCH
  • Home
  • 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 8400717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:37:49+00:00 2026-06-09T21:37:49+00:00

I wish to make the following list from an array returned from an ajax

  • 0

I wish to make the following list from an array returned from an ajax call.

<ul id="list">
  <li><input type="checkbox" name="rss" value="231" />bla</li>
  <li><input type="checkbox" name="rss" value="321" checked="checked" />ble</li>
  <li><input type="checkbox" name="rss" value="431" />abc</li>
</ul>

Both of the following will work (I might need to tweak but they are close. Is one method preferred over the other? Is there something better altogether? Thanks

var l=$("#list");
l.html('');
$(data).each(function(){
  l.append('<li><input type="checkbox" name="rss" checked="'+((this.selected)?'checked':null)+'" value="'+this.id+'" />'+this.channel+'</li>');
  //Or
  l.append($("#rss-clone").clone(true).removeAttr('id').find('input').val(this.id).attr('checked',(this.selected)?'checked':null).parent().text(this.channel));
},'json');

//required for clone solution only:

<ul class="hidden"><li id="rss-clone"><input type="checkbox" name="rss" value="" />bla</li></ul>
  • 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-09T21:37:50+00:00Added an answer on June 9, 2026 at 9:37 pm

    See also: jQuery and dynamic elements vs display css attribute

    The takeaway is that dynamically creating doms on the fly adds overhead on the client, whereas cloning existing doms is fast on the client but has the overhead of having to render and download them in advance.

    None is the better than the other, which one is more suitable for you depends on your project; if you care more about client performance than a few extra bytes to be downloaded per request you would do good choosing the cloning method for instance.

    As far as I can tell however, the client performance is not severely affected by any of the methods, cloning is ever so slightly faster but dynamically creating elements is not horribly slow by any means. Unless you are creating 100s of these the choice may just come down to a matter of taste, ie what feels better for you.

    One thing to note however is that unless you need to create many very different elements, cloning is a more convenient method in that you can easily style and modify the elements afterwards if the markup is not embedded in your JS code.

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

Sidebar

Related Questions

I have the following HTML. <input type=text class=embeddedLabel /> And I wish to tie
I have several variables coming from an array in $POST_['array'] i wish to make
I wish to make sure that my data has a constraint the following check
I wish to make a self contained LAMP distro software package from source with
I am able to do the following, $.ajax({ url : 'http://search.twitter.com/search.json', data:{ q:'from:user1 OR
i wish to parse following XML <?xml version=1.0 encoding=UTF-8?> <product xmlns=http://products.org> <make xmlns=http://camera.org> <model>Camry</model>
Assuming the following example array: {/documents, /documents/files, /pictures} I wish to create a multidimensional
I wish to make the uploaded file contents only viewable on the browser i.e
I wish to make a drag and select application in GWT where I wish
I wish to make a nested for loop in order to process some files.

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.