문제

I don't know why does this code not work on chrome and safari, but in mozilla works fine?

$('#id').css('background-image','url(/image.png)');

I also tried this

$('#id').css('background-image','url("/image.png")');
$('#id').css('backgroundImage','url("/image.png")');
$('#id').css('backgroundImage','url(/image.png)');

but still doesn't work.

올바른 솔루션이 없습니다

다른 팁

where do you put the image file (image.png)? If it is in the same directory as in the .html file, you could try this

$('#id').css('background-image','url("image.png")');

$('selector').css('backgroundImage','url(images/myImage.jpg)');
$('selector').css({'background-image':'url(images/myImage.jpg)'});

The latter example allows for multiple rules. Check out the API for more details.

Edit: Make sure your path(s) to your image(s) are correct by inspecting the console. That should tell you if you are getting a 404.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top