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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:21:04+00:00 2026-05-27T13:21:04+00:00

I need 100 small divs for my chart, every time I generate them, I

  • 0

I need 100 small divs for my chart, every time I generate them, I they all appear as the same height; the last value from the array.

var valuesG = new Array(100);
for (i = 0; i < valuesG.length; i++ ) {
    valuesG[i] = Math.floor(Math.random() * 101);   
    $("#second").append("<div class='single'></div>");
    $(".single").css('height', valuesG[i])
}

Any ideas why this is happening?

  • 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-27T13:21:04+00:00Added an answer on May 27, 2026 at 1:21 pm

    You are applying the new height to ALL the .single elements in every iteration. In the last iteration, they end up having the same height.

    You could do it like this:

    $('<div class="single">')
        .css('height', valuesG[i])
        .appendTo($('#second'));
    

    Also, your code is not very efficient, take a look at this:

        var valuesG = [], //array literal
            $elements = $(); //empty jQuery object
    
        for (var i = 0; i < 100; i++) { //we don't have to query array length each iteration
            valuesG[i] = Math.floor(Math.random()*101); 
    
            //collect the elements into a jQuery object
            $elements = $elements.add($('<div class="single">').css('height', valuesG[i]));
        }
    
        $elements.appendTo($("#second")); //insert to DOM once - much quicker
    

    jsFiddle Demo

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

Sidebar

Related Questions

I need to remove the last character if the textfield length exceeds 100,I used
I have about 100 databases (all the same structure, just on different servers) with
i need to print out numbers 1-100 in a random order. the print statement
I need to execute a command 100-200 times, and so far my research indicates
I need to merge and sort lists of 100,000+ words lexicographically. I currently do
i need to trim a string to its first 100 characters using jquery/javascript. also
I need to run a PHP loop for a total of 100, 000 times
I need to wrap a dynamically allocated array(from a = new double[100] for example)
I have 1000 rows of data but need to only display 100 rows at
I have datatable with column name tag and 100 rows of data.I need to

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.