My card game triggers the click event for all cards once the DOM is loaded. My code originally looked like
$.each(cardArray, function(i,value){
var activeCard = $('<div class="cardContainer" title="'+cardArray[i]['name']+'" >'+cardArray[i]['damage']+'</div>');
activeCard.click(doStuff(i,activeCard));
}
but after finding some other helpful responses to the same issue I discovered this was due to the () resulting in the function execution so my new call should look like
$.each(cardArray, function(i,value){
var activeCard = $('<div class="cardContainer" title="'+cardArray[i]['name']+'" >'+cardArray[i]['damage']+'</div>');
activeCard.click(doStuff);
}
Unfortunately this means I'm left without being able to pass variables I need. What are possible solutions or best practices here?