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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:20:58+00:00 2026-06-17T10:20:58+00:00

JSFiddle here: http://jsfiddle.net/xgTt2/3/ I have a $.each nested inside of a $.each , and

  • 0

JSFiddle here: http://jsfiddle.net/xgTt2/3/

I have a $.each nested inside of a $.each, and I’m not sure why the second $.each is running twice. Any ideas?

var serverResponse = [{"Id":"aaa","OrderItems":[{"Id":1,"Description":"Salad"},{"Id":2,"Description":"Pizza"}]},{"Id":"bbb","OrderItems":[{"Id":3,"Description":"Salad"},{"Id":4,"Description":"Pizza"}]}];

$.each(serverResponse, function (index) {
  var pos = serverResponse[index];

  $('#placeholder').append('<p>' + pos.Id + '</p>')

  $.each(pos.OrderItems, function (index) {
     $('.orderitem').append('<p>' + this.Id +  
                       ' ' + this.Description + '</p>')
  });

});

The above javascript is producing the following output:

aaa
1 Salad
2 Pizza
3 Salad
4 Pizza
bbb
3 Salad
4 Pizza

I want this:

aaa
1 Salad
2 Pizza
bbb
3 Salad
4 Pizza

Any idea what I’m doing wrong? Here’s a working example of the problem: http://jsfiddle.net/xgTt2/3/

  • 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-17T10:21:00+00:00Added an answer on June 17, 2026 at 10:21 am

    Near the end, you have two elements with the class orderitem. Using $('.orderitem').append() will append to both of them.

    Instead, you want to append to the last element you created.

    var $order_item = $('<p class="orderitem">' + pos.Id + '</p>');
    $('#placeholder').append($order_item);
    
    $.each(pos.OrderItems, function (index) {
      $order_item.append('<p>' + this.Id +  
                           ' ' + this.Description + '</p>');
    });
    

    http://jsfiddle.net/xgTt2/4/

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

Sidebar

Related Questions

I have a jsfiddle here : http://jsfiddle.net/hhimanshu/eLhLS/1/ Current: On keypress, it keeps on appending
See here: http://jsfiddle.net/zYcJm/ The jQuery should be validating each field to check if they
I have a jsfiddle here: http://jsfiddle.net/aND4g/2/ I am having a problem with a text
I have a jsfiddle here: http://jsfiddle.net/XM8hG/33/embedded/result/ To view code of fiddle click here: http://jsfiddle.net/XM8hG/33/
I have a jsfiddle here: http://jsfiddle.net/ybZvv/22/ The situation I have is that if you
I have a JSfiddle here: http://jsfiddle.net/mW9XD/ I'm struggling to get the amount of hours
I have a jsfiddle here: http://jsfiddle.net/ybZvv/61/ Please follow steps in fiddle: When you open
I have a jsfiddle here http://jsfiddle.net/cbyJD/74 The problem I am having is that it
I have a jsfiddle here: http://jsfiddle.net/asaakius/5nGYS/7/ You'll notice this little div $(#menu) with the
See JsFiddle here http://jsfiddle.net/WtgbV/2/ In words: I have some ajax call, and in the

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.