Setting background-image using jQuery CSS property

css, javascript, jquery

Solution

You probably want this (to make it like a normal CSS background-image declaration):

$('myObject').css('background-image', 'url(' + imageUrl + ')');

Problem

I have an image URL in a `imageUrl` variable and I am trying to set it as CSS style, using jQuery: ``` $('myObject').css('background-image', imageUrl); ``` This seems to be not working, as: ``` console.log($('myObject').css('background-image')); ``` returns `none`. Any idea, what I am doing wrong?

Original source

Related problems