Reputation: 1
i wrote the following code, only problem it places the div before the closing tag and i want it to be at the beginning.
<script type="text/javascript" language="javascript">
window.onload = function createDiv1() {
var divTag1 = document.createElement("div");
divTag1.id = "mid section";
divTag1.setAttribute("align", "center");
divTag1.className = "dynamicDivmid";
divTag1.innerHTML = "pp";
document.body.appendChild(divTag1);
}
Upvotes: 0
Views: 220
Reputation: 1289
Try like this:
document.body.insertBefore(divTag1, document.body.firstChild)
Upvotes: 7