Reputation: 701
In my script I have variable image_src
like
var image_src = 'img/test.jpg';
then I tried to add background-image
to block using jQuery
$('#lightbox').css({
'background-image': '(../' + image_src + ')'
});
but it doesn't work. What's wrong ?
Upvotes: 2
Views: 86
Reputation: 12300
What error message are you getting?
This should work:
$('#lightbox').css({
'background-image': 'url(../' + image_src + ')'
});
Upvotes: 1
Reputation: 78525
You need to set your CSS property with a URL datatype:
$('#lightbox').css({
'background-image': 'url(../' + image_src + ')'
});
Upvotes: 1
Reputation: 82231
You are missing url
in set value.try this:
$('#lightbox').css({
'background-image': 'url(../' + image_src + ')'
});
Upvotes: 1