Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
85
rated 0 times [  92] [ 7]  / answers: 1 / hits: 62663  / 12 Years ago, thu, april 26, 2012, 12:00:00

In the below code objTo is a div to which i need to insert multiple number of div.
when i use the code for the first time its working.but on the next time its overwriting the existing code.



     <script>

var divtest= document.createElement(div);
divtest.innerHTML = <div>new div</div>
objTo.appendChild(divtest)
</script>


Where am i going wrong?


More From » appendchild

 Answers
245

I have made a very simple working version for you :



http://jsfiddle.net/hQKy9/



Multiple clicks works the whole time :



Script



function addDiv() {
var objTo = document.getElementById('container');
var divtest = document.createElement(div);
divtest.innerHTML = new div;
objTo.appendChild(divtest);
}


Html



<div id=container></div>

<input type=button onclick=addDiv(); value=Click here to add div/>

[#85966] Wednesday, April 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristinadomoniquel

Total Points: 320
Total Questions: 94
Total Answers: 94

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
cristinadomoniquel questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
Mon, Aug 17, 20, 00:00, 4 Years ago
;