简体   繁体   中英

Setting CSS background dynamically in Javascript

i have a Cordova Win8 Phone app, and in it.. i would like to set the background image attritube for the stylehseet dynamically.

#profile {
  background-image: url('**____SET__DYNAMICALLY____**');
  background-repeat: no-repeat;
  background-position: top center;
  position: relative;
}

I tried below, but that doesnt work.

      document.getElementById("#profile")="background-image: url('" + bgimage + "');";

Any ideas on what could be up? thanks!

document.getElementById("profile").style.backgroundImage
    = "url(" + bgimage + ")";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM