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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:53:55+00:00 2026-06-11T20:53:55+00:00

My JQuery code creates multiple divs on the click of a button using a

  • 0

My JQuery code creates multiple divs on the click of a button using a while-loop.

$(document).on("click",".ball_link", function makeDiv(){
count=0;
//ajax code to fetch no. of divs to be created from table

    while(count< no_of_divs)
    {

    //code to calculate random x,y coordinates and save them to posx and posy

    var newdivid='div'+count;
    $newdiv = $('<div/>').css({
    'position':'absolute',
    'left':posx+'px',
    'top':posy+'px',
    'display':'none',
    'background':'ball.png'
    }).appendTo( '.page-wrap' ).fadeIn(600).effect("bounce", { times:6, distance:15 },300);
    count++;
    }
});

The problem is that if the no_of_divs is for eg 3, then all 3 divs appear at the same time on the page. How can I force them to come one by one, without removing the while loop?

  • 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-11T20:53:56+00:00Added an answer on June 11, 2026 at 8:53 pm

    Just a slight change – add a delay to the animation…

    $(document).on("click",".ball_link", function makeDiv(){
    count=0;
    //ajax code to fetch no. of divs to be created from table
    
        while(count< no_of_divs)
        {
    
        //code to calculate random x,y coordinates and save them to posx and posy
    
        var newdivid='div'+count;
        $newdiv = $('<div/>').css({
            'position':'absolute',
            'left':posx+'px',
            'top':posy+'px',
            'display':'none',
            'background':'ball.png'
        }).appendTo( '.page-wrap' ).delay(900 * count).fadeIn(600).effect("bounce", { times:6, distance:15 },300);
        count++;
        }
    });
    

    I set the delay to 900 * count as 900 is the total animation time for the fade and the bounce. Play about with that value to get it how you like it 🙂

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

Sidebar

Related Questions

jQuery code add new virtual object .add to object .main $(document).ready(function(){ $('.main').on('click', '.add', function
jQuery Code: $(document).ready(function(){ $.getJSON('dat.js', function(data) { var obj = JSON.parse(data); alert(obj[0].title); }); }); My
I have found a code to show Google maps with multiple markers using JQuery
I have the next code dynamically created using JQuery. Theere are multiple row class
I am writing a script using jQuery to add multiple control boxes(divs) to a
I am using jquery to create a custom dropdown with the code below. I
jQuery code: function ajaxsubmit(){ $.ajax({ url: /update, type: POST, dataType: html }).success(function(data) { $('#result').html(data);
My JQuery code is posting, because the success function is firing. The problem is
My jquery code It's not working when $(a).on(hover,function(){$(this).css(background,#ccc);},function(){$(this).css(background,#fff)}); But is working when $(a).hover(function(){$(this).css(background,#ccc);},function(){$(this).css(background,#fff)}); How
I want to make the div's expand/collapse on the jquery click function I have

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.