1

I'm making BlackJack in JavaScript, Jquery, CSS and HTML. but I'm stuck with showing the card. I need to place them into a array like:

var imgArray = new Array("images/harten/harten2.png","images/harten/harten2");

now I want to change the background-image from a div I did it this way:

    $('#cardplace1').css("background-size", "contain");
$('#cardplace1').css("background-image", "url(imgArray[0])");

for some weird reason it won't work, any tips?

Thanks !

1
  • Example Commented Nov 10, 2013 at 16:05

1 Answer 1

1

You can try this,

 $('#cardplace1').css("background-image", "url('" + imgArray[0] + "')");

You can set in single statement like,

$('#cardplace1').css({
    "background-image" : "url('" + imgArray[0] + "')",
    "background-size" : "contain"
});
Sign up to request clarification or add additional context in comments.

3 Comments

Then the console (in firefox) gives the error: ReferenceError: invalid assignment left-hand side
Try, $('#cardplace1').css("background-image", "url('" + imgArray[0] + "')"); this once
$('#cardplace1').css("background-image", "url('" + imgArray[0] + "')"); Worked perfectly, THANKS ALOT !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.