+ 1

How do i create multiple divs when i click

25th Jul 2017, 3:08 PM
Tiko Markosyan
Tiko Markosyan - avatar
2 Respostas
+ 5
Create and append one element: var div = document.creatElement("div"); document.body.appendChild("div"); To create more, just wrap a for loop around it: for(var i = 0; i < 3; i++) { //the same as above }
25th Jul 2017, 5:56 PM
The Coding Sloth
The Coding Sloth - avatar
+ 5
Check this code I've fixed about a month ago: https://code.sololearn.com/WPG5hMIJRXj4/?ref=app It show a basic way to do duplicates of <img>, but the principle is same as for any html code ;) Among the cases context, using DOM API to handle elements as suggested by @The Coding Sloth may be better suited, but the 'innerHTML' way is easiest to use at first... you can later improve your code if needed ^^
26th Jul 2017, 8:52 AM
visph
visph - avatar