I'm trying to pass in a custom string to the .css jQuery function. So instead of doing this:
$('#image1').css('background', 'url("img1.png") no-repeat');
I want to do this:
var image = "'url(\"img1.png\") no-reapt'"
$('#image1').css('background', image);
But it's not working. The reason I want to do it like that is because I have 6 elements with 6 different possibilities of different images so I want to add them dynamically. So it would actually look more like this, my variable:
var image = "'url(\"" + this.image.imgs[value[i]] + "\") no-repeat'"
$('#image1').css('background', image);
And it would be inside a loop
Remove the extra '' symbols. You don't need them. In your string, which is a css style - '' symbols are not valid and they cause not to apply the style.
var image = "url(\"img1.png\") no-repeat";
$('#image1').css('background', image);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With