+ 1
How do i create multiple divs when i click
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
}
+ 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 ^^