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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:53:16+00:00 2026-05-29T08:53:16+00:00

If for example I have the following HTML structure <ul class=actions> <li class=action>Action 1</li>

  • 0

If for example I have the following HTML structure

<ul class="actions">
    <li class="action">Action 1</li>
    <li class="action">Action 2</li>
    <li class="action">Action 3</li>
</ul>

And the following Javascript

$('.actions .action').each( function() {
    perform an ajax request // intended pseudocode
    if ajax returns some more actions { // intended pseudocode
            $('.installer-actions').append('<li class="action">Another Action</li>');
    }
});

The added <li class="action"> elements are not included in the each() obviously. Is there a way I can involve them in the current loop or will I need to loop through again and ignore the original .action elements?

  • 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-29T08:53:17+00:00Added an answer on May 29, 2026 at 8:53 am

    You can’t add them to the object that each is iterating (the documentation doesn’t say what happens if you add to the existing set, so we can’t rely on whatever it currently does), but you can readily enough break out your code to a function which you can call in both places:

    $('.actions .action').each(doCoolThing);
    function doCoolThing() {
        var newAction;
    
        // perform an ajax request // intended pseudocode
        if (ajax_returns_some_more_actions) { // intended pseudocode
            newAction = $('<li class="action">Another Action</li>');
            $('.installer-actions').append(newAction);
            doCoolThing.call(newAction[0]);
        }
    }
    

    There we’re calling doCoolThing on the new action, making this within the call the new raw DOM element (just like each does).

    It’s worth noting, though, that your ajax request will be asynchronous (unless you set async to false, which is a bad idea), which could impact how you would structure things. We’d have to see real code for the pseudo-code above to help there, but the concept above is sound.

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

Sidebar

Related Questions

I have following structure of an HTML document: <body> <div class=main> <div class=left></div> <div
I have the following HTML structure: <div id=ctr__Wrapper class=wrapper> <div id=ctr class=control clickable> <img
I have following structure with example data: id season_id title 1 1 Intro 2
I have the following example class: Test.h: @interface Test : UIButton { NSString *value;
I have the following example code: class A(object): def __init__(self, id): self.myid = id
I have the following HTML node structure: <div id=foo> <div id=bar></div> <div id=baz> <div
I am a newbie in this department.I have following folder structure root root\html root\html\html
I have the following DOM structure / HTML, I want to get (just practicing...)
I have the following structure: <table> <tr> <td>first</td> <td class=price>__</td> <td><input type=text class=quantity></td> <td
I have the following simple structure: Applicant Possition ApplicantPosition and ApplicantPositionHistory The 3rd class

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.