I am trying to make a image grid with download buttons using javascript to put them in html.
I tried insertBefore.
var list = ["https://via.placeholder.com/50", "https://via.placeholder.com/75", "https://via.placeholder.com/100", "https://via.placeholder.com/125"];
var template, item, item1, item2, fin, i, target, ta;
template = document.getElementById("item");
item = template.content.getElementById("grid-itm");
item1 = template.content.getElementById("imgtit");
item2 = template.content.getElementById("linktit");
target = document.getElementById("gc");
for (i = 0; i < list.length; i++) {
target = document.getElementById("gc");
ta = list[i];
item1.src = ta;
item2.href = ta;
item.appendChild(item1);
item.appendChild(item2);
target.appendChild(item);
}
<template id="item">
<div class="grid-item" id="grid-itm">
</div>
<img src="" id="imgtit">
<a href="" id="linktit"><p>Download</p></a>
</template>
<div class="grid-container" id="gc"></div>
In .grid-container should be all my pictures, but it's only the last from the list.