ga-wdi-exercises / project1

[project] GA- Project 1
3 stars 75 forks source link

issue with loading images into array and assigning them to a background-image property #160

Closed codedre closed 9 years ago

codedre commented 9 years ago

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++;
});
RobertAKARobin commented 9 years ago

You're missing +: "url(" + gameSquares[i] + ")"

codedre commented 9 years ago

Thank you!