clone div

hello
i need to duplicate div when i press button it all works
but how to make it counts +1 name not id

my code:

Add More Countries

<?php ...... foreach($countries as $key => $value) { ?> <?= htmlspecialchars($value) ?> <?php } ?>
document.getElementById('button').onclick = duplicate;
					var i = 0;
					var original = document.getElementById('duplicater');

					function duplicate() {
						var clone = original.cloneNode(true); // "deep" clone
						clone.id = "duplicetor" + ++i; // there can only be one element with an ID
						original.parentNode.appendChild(clone);
					}
					</script>

it duplicates this div

but i need it duplicates


Is this a repost? I’m sure I just saw this, maybe on stack overflow?

Annyway, I think the simplest way to do this would be to set the select template (duplicater) to be the select element, instead of the wrapper div.

Then in the duplicate function you need to add a “name” attribute with the name you want. Either using empty brackets if you should just be able to select multiple, or add an incrementing number if you for some reason need that

Sponsor our Newsletter | Privacy Policy | Terms of Service