Setting background-image using jQuery CSS property

前端 未结 11 2096
渐次进展
渐次进展 2020-11-22 10:34

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\', image         


        
11条回答
  •  故里飘歌
    2020-11-22 10:52

    Don't forget that the jQuery css function allows objects to be passed which allows you to set multiple items at the same time. The answered code would then look like this:

    $(this).css({'background-image':'url(' + imageUrl + ')'})

提交回复
热议问题