181
rated 0 times
[
186]
[
5]
/ answers: 1 / hits: 19172
/ 13 Years ago, sat, february 18, 2012, 12:00:00
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.
More From » jquery