Mensur Mensur - 3 months ago 8
Javascript Question

Add background image property to Jquery

I would like to know how to add css background-image:url("xxxxx") property to my code.

jQuery('#'+$trackID+' .sc_thumb').attr('src',$thumb_url);
jQuery('#'+$trackID+' .sc_container').css('display','block');


What i would like to do is to add to the second row property background-image:url("") and put the $thumb_url value inside so I can have a background from that image.

I guess this should be added to .css property somehow, and I have tried different ways but I can't get this to work. Any ideas?

Answer

you can try

jQuery('#'+$trackID+' .sc_container')
.css({
    'display':'block',
    'background-image' : 'url('+ $thumb_url +')'
    });

or

jQuery('#'+$trackID+' .sc_container')
.css('display','block')
.css('background-image' , 'url('+ $thumb_url +')');
Comments