0

I am building a GUI that pulls in information from a JSON file and populates divs on the screen. I have buttons that are being dynamically created and they all have their own unique ID's (ex: button1, button2, button3, etc. etc.) I want each of these buttons to pass unique information to separate div based on its corresponding information pulled from the JSON. I hope that makes sense.

As I am looping through the JSON I am building the buttons like:

var viewBtn = document.createElement("button");
viewBtn.setAttribute("class", "button");
viewBtn.setAttribute("id", "button" + i);
viewBtn.innerHTML = "View More";
viewBtn.onclick = function()
{
  uniqueAction(i);
}
product.appendChild(viewBtn);

}

Right now every button is storing the last number passed by the for loop. Thanks ahead of time for any help anyone can lend!!

NightMarcher
  • 159
  • 4
  • 16

0 Answers0