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.
Try this.. hope this is what you are trying to do..