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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:50:08+00:00 2026-05-15T09:50:08+00:00

I am using ajax to insert a series of informational blocks via a loop.

  • 0

I am using ajax to insert a series of informational blocks via a loop. The blocks each have a title, and long description in them that is hidden by default. They function like an accordion, only showing one description at a time amongst all of the blocks.

The problem is opening the description on the first block. I would REALLY like to do it with
javascript right after the loop that is creating them is done. Is it possible to manipulate
elements created ofter an ajax call without using the callback?

<!-- example code-->
<style>
    .placeholder, .long_description{
    display:none;}
</style>
</head><body>
<script>  /* yes, this script is in the body, dont know if it matters */
$(document).ready(function() {
    $(".placeholder").each(function(){  // Use the divs to get the blocks
        var blockname = $(this).html();  // the contents if the div is the ID for the ajax POST
        $.post("/service_app/dyn_block",'form='+blockname, function(data){
            var divname  = '#div_' + blockname;
            $(divname).after(data);
            $(this).setupAccrdFnctly(); //not the actual code
        });
    });

    /* THIS LINE IS THE PROBLEM LINE, is it possible to reference the code ajax inserted */
    /*  Display the long description in the first dyn_block */
    $(".dyn_block").first().find(".long_description").addClass('active').slideDown('fast');
});
</script>
<!-- These lines are generated by PHP -->
<!-- It is POSSIBLE to display the dyn_blocks -->
<!-- here but I would really rather not -->
<div id="div_servicetype" class="placeholder">servicetype</div>     
<div id="div_custtype" class="placeholder">custtype</div>           
<div id="div_custinfo" class="placeholder">custinfo</div>           
<div id="div_businfo" class="placeholder">businfo</div>
</body>
  • 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-15T09:50:09+00:00Added an answer on May 15, 2026 at 9:50 am

    The problem is that as AJAX is asynchronus (by default)

    $(".dyn_block").first().find(".long_description").addClass('active').slideDown('fast');
    

    will execute before there is any data. So you cannot avoid callbacks.

    Instead of polling you could define the following function

    var amount = $(".placeholder").size();
    function ajaxDone() {
     amount--:
     if(amount == 0) {
        $(".dyn_block").first().find(".long_description").addClass('active').slideDown('fast');
     }
    }
    

    If you want to slideDown the first one when all the processing is done.

    So the script would look like this

    <script>  /* yes, this script is in the body, dont know if it matters */
    
        var amount = $(".placeholder").size();
        function ajaxDone() {
           amount--:
           if(amount == 0) {
             $(".dyn_block").first().find(".long_description").addClass('active').slideDown('fast');
           }
        }
    
    
            $(document).ready(function() {
                $(".placeholder").each(function(){  // Use the divs to get the blocks
                    var blockname = $(this).html();  // the contents if the div is the ID for the ajax POST
                    $.post("/service_app/dyn_block",'form='+blockname, function(data){
                        var divname  = '#div_' + blockname;
                        $(divname).after(data);
                        $(this).setupAccrdFnctly(); //not the actual code
                    });
                });
    
                /* THIS LINE IS THE PROBLEM LINE, is it possible to reference the code ajax inserted */
                /*  Display the long description in the first dyn_block */
    
            });
            </script>
    

    EDIT: Regarding you comment about not knowing wether it matters or not to have your javascript on the HTML, check this SO question

    As Nick suggested there is a better way to achieve the same thing (instead of using the ajaxDone function)

    $(document).ajaxStop(function() { 
        $(".dyn_block").first().find(".long_description").addClass('active').slideDown('fast'); 
        $(this).unbind('ajaxStop'); 
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ajax requests to populate modal popup windows with data that users have
I have a form that inserts data into my DB using AJAX and PHP.
I have a main web page (Base Page) that makes an ajax call (using
I am using Prototype Ajax Updater (via Rails link_to_remote) to insert some HTML returned
I used this example : http://woork.blogspot.com/2007/10/insert-record-into-database-using-ajax.html it is working when using with Numbers for
I am using Ajax tab container control with 3 tabs. I have placed a
When I'm using AJAX, I typically do something before each request to let the
I have started using ajax/jQuery in our websites / application. There are many plugins
I have appended content (using ajax) to my document and my events are not
My site has a form which insert records in a database using ajax, at

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.