Search code examples
javascripthtmlcsscordovastylesheet

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!


Solution

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