Pergunta

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.

Nenhuma solução correta

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top