You can setAttribute property to assign each property of the DIV rather then appending it in the string.
<style type="text/css">
.divclass
{
background: #F0E68C;
border: solid 1px #c0c0c0;
padding: 0.5em;
text-align: center;
float: left;
}
</style>
<script src="Scripts/jquery.js" type="text/javascript"></script>
<script type="text/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');
div.setAttribute("class", "divclass");
div.setAttribute("id", id);
div.setAttribute("height", divheight);
div.setAttribute("width", divwidth);
div.innerHTML = id;
$('#divmain').append(div);
eh = eh + divheight;
fh = fh + divheight;
id++;
}
document.createElement("<br />");
document.body.appendChild(divmain);
}
}
</script>
<body onload='javascript:createDiv();'>
<form id="form1" runat="server">
<div id="divmain"></div>
</form>
</body>