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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:47:03+00:00 2026-05-30T00:47:03+00:00

I want to create div dynamically based on some calculations.I am able build div’s

  • 0

I want to create div dynamically based on some calculations.I am able build div’s dynamically but the only issue is it’s not taking height and width on fly.please any one share their view or code if possible.

Here’s the script which i used for your reference.

<script type="text/javascript" language="javascript">
   function createDiv()
   {
            var totalheight=400;
            var totalwidth = 600;
            var height = 80;
            var width = 40;
            var divheight = totalheight / height;
            var divwidth = totalwidth / width;
            var id=1;

            for(var i=1;i<=divheight;i++)
            {
                var eh=divwidth;
                var fh=1;
                for (var w = 1; w <= divwidth; w++)
                {
                   var div=document.createElement("<div id='"+id+"' style=\"background:#F0E68C;width:'"+width+"'px;height:'"+height+"'px;border:solid 1px #c0c0c0;padding: 0.5em;text-align: center;float:left;\"></div>"); 
                   document.body.appendChild(div);
                   eh=eh+divheight;
                   fh=fh+divheight;
                   id++;
                }
                 var div1=document.createElement("<br/>");
                 document.body.appendChild(div1);
            }     
    }
    </script>

Thanks in advance.

  • 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-30T00:47:05+00:00Added an answer on May 30, 2026 at 12:47 am

    Try this.. hope this is what you are trying to do..

    <html>
    
    <script type="text/javascript" >
     function newDiv(){
                var totalheight=400,ht = 80 , totalwidth = 600 ,wd = 40 ,i;
                var divheight = totalheight / ht;
                var divwidth = totalwidth / wd;
                var id=1;
    
                for(var i=1;i<=divheight;i++)
                {
                    var eh=divwidth;
                    var fh=1;
                    for (i = 1; i <= divwidth; i++)
                    {
                       var div=document.createElement("div")
                       div.setAttribute("id","newDivId"+id)
                       div.setAttribute("class","newDiv")
                       div.style.width =wd+"px";
                       div.style.height =ht+"px";
                       document.body.appendChild(div);
                       eh=eh+divheight;
                       fh=fh+divheight;
                       id++;
                    }
                     var div1=document.createElement("<br/>");
                     document.body.appendChild(div1);
                }     
        }
    </script>
    <style type="text/css">
    .newDiv{
        background-color:#F0E68C;
        border:1px solid #c0c0c0;
        padding: 0.5em;
        text-align:center;
        float:left;
    }
    </style>
    <body>
        <input type="button" onclick="newDiv()" value="Click Me">
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to dynamically create a div element with id=xyz . Now before creating
I have a container div inside of which i want to dynamically create other
I create an element dynamically: var $el = $('<div class=someclass></div>'); I want to append
I have a menu bar and I want to create a div for each
i want to create a new '.b' div appendTo document.body, and it can dragable
I have a script that create a new div element. Then, I want to
I want to create a simple http proxy server that does some very basic
I want to show some objects, which texture will be dynamically generated. Is there
I've got some links I want to have dynamically open in a jQuery UI
I think that this should be easy, but I'm not able to get it

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.