Skip to main content
1 of 3
Tamras Merin
  • 771
  • 13
  • 32

Change background image dynamically in IE

I'm trying to get the a page to display a background image based on Holiday.

When I used the DevTools in IE and pasted the following in #s4-workspace in css, nothing happened. But it worked when I pasted it under .ms-backgroundImage

background-image: url("bgimage.jpeg");

Below is the code that works in Chrome and Edge but not in IE11.

if (dtTodayHol >= holSD && dtTodayHol <= holED) {
    document.getElementsByClassName('ms-backgroundImage')[0].style.backgroundImage = "url('" + holBG + "')";
}

Also tried it on #s4-workspace, same result:

    document.getElementById('s4-workspace').style.backgroundImage = "url('" + holBG + "')";

and also tried below but didn't work in Chrome, Edge, or IE:

.style.background = "url('" + holBG + "') no-repeat"
Tamras Merin
  • 771
  • 13
  • 32