I tried adding each image into an array then calling that array index of the image and set it to the bg image property of the td element on click. I expected correct bg image to appear. Instead the default bg image appears or no image appears
var menuPath = "../images/menu/";
var gameSquares = [menuPath + "Sandwich1.png", menuPath + "Burger2.png"];
// some lines down
$("table").on("click", function(){
var target = $(event.target);
var i=0;
target.addClass('flipped').css('background-image', "url("gameSquares[i]")");
i++;
});
I tried adding each image into an array then calling that array index of the image and set it to the bg image property of the td element on click. I expected correct bg image to appear. Instead the default bg image appears or no image appears