Lior Shmulever
Lior Shmulever

Reputation: 1

how can i dynamically add a div to my page after the body tag?

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

Answers (1)

Hacker Wins
Hacker Wins

Reputation: 1289

Try like this:

document.body.insertBefore(divTag1, document.body.firstChild)

Upvotes: 7

Related Questions