I am trying to change the b开发者_StackOverflow中文版ackground image of an element through jquery like this;
$j(this).css('background-image','url(images/client_box_grad.gif)');
However when it renders it seems to drop speech marks around the the url, eg
$j(this).css('background-image','url("images/client_box_grad.gif")');
And this means the image isn't visible - if I remove the speech marks in Firebug then the image shows up.
Any ideas ?
The double quotes are not necessary:
$(this).css('background-image', 'url(/images/client_box_grad.gif)');
You should make sure that you have specified a valid image url. Here's a demo.
This is what I had to do to get it to work:
$(function(){
$('body').css({backgroundImage : 'url(/media/bill.jpg)'});
});
Try these:
$(this).css('background-image','url(images/client_box_grad.gif)');
// OR
$(this).css('background', 'url("images/client_box_grad.gif")');
精彩评论