I generate a list of Magic cards from a Json file.
for (i in set.cards) {
leftCardElement = document.createElement("p");
leftCardElement.innerHTML = set.cards[i].points + " " + set.cards[i].name + " ";
leftCardElement.addEventListener("click", leftCardClicked);
}
function leftCardClicked(event) {// access card.cost and other things }
The problem is that when the leftCardElementClicked()
method is called I'd like to be able to have access to the set.cards[i]
object. The this
object seems to refer to the element that I clicked on inside of leftCardElementClicked()
. Is there some way that I can pass the index i
to the event handler so I can get my card object?