Imagine there is an array with photos, and we want to create a list that shows all of them:
photoOptions = ["Blue.jpg", "Red.jpg", "Green.jpg"]
Here's the code that I have currently:
photoOptions = ["Red.jpg", "Blue.jpg", "Green.jpg"]
var thumbnailList = document.getElementById('product-options');
var elem = document.createElement("img");
var listItem = document.createElement("li").appendChild(elem)
var clone;
photoOptions.forEach(function(item, index) {
elem.src = 'http://placehold.it/100?text=' + index;
clone = listItem.cloneNode();
thumbnailList.appendChild(clone);
});
<ul id="product-options"></ul>
It creates the ul I want, but instead of the <img>'s living inside of an <li>, they are just listed as <img> elements with no parent <li>. What can I do to make the code return a <ul> with <li>'s that each contain a <img> tag?