Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

Can anyone help me with the code, it is working for first time and next time it is overwriting the code:

 <script>

var divtest= document.createElement("div");        

divtest.innerHTML = "<div>new div</div>"         

objTo.appendChild(divtest)

    </script>

Any help would be appreciated.

1 Answer

0 votes
by (26.7k points)

You can use the below code, which will help you to achieve it:

function addDiv() {

    var objTo = document.getElementById('container');

    var divtest = document.createElement("div");

    divtest.innerHTML = "new div";

    objTo.appendChild(divtest);

}

I hope this will help.

Want to become a Java Expert? Join Java Course now!!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Aug 24, 2019 in Web Technology by Tech4ever (20.3k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...