So I'm trying to create a sort of deck creator in JS, I have the prototype, but I want to make it a bit more modular. So I made a else loop to create DOM buttons. The problem I'm having is I can't seem to figure out how to get the id/any number from the SPECIFIC button I pressed.
var cardName = ["Card 1", "Card 2", "Card 3", "Card 4", "Card 5", "Card 6"]
var Card;
var isInDeck = ["false", "false", "false", "false", "false"];
var Deck = [];
for (var i = 0; i < cardName.length; i++) {
var button = document.createElement("button");
button.innerHTML = cardName[i];
button.classList = "Button";
button.setAttribute('id', cardName[i]);
document.getElementById("buttonPlace").appendChild(button);
}
EDIT, I have already tried adding
button.onClick = function () {Card = i;}
after it in the for loop, and it didn't work,