I'm trying to update my background image (each day new image, Monday thru Sanday). I know there is some javascript code to update images on daily basis but how I can change the background image.
Thanks for any advise.
I'm sorry but the code it's confusing to me. Can you walk me thru this code? I have 7 images in my folder what I like to use for the baackground of my table.
Well, I'm not the best expert on Javascript, but here's the important parts:
Code:
var el=document.getElementById('midimage');
...
<div id="midimage"> </div>
In this example, a div element, which just defines an arbitrary block, is given the ID "midimage". A space is placed within the div to give it meaningless content. That's the .
In the javascript above, a variable named el is created that points to the element with the name 'midimage'. That's the div defined below in the HTML.
Code:
var bg="url("xyz.jpg")";
el.style.setProperty('background-image', bg, null);
I modified this next bit to be more simple. The variable bg is created and set to "xyz.jpg". Set this to the image you want to change to. Then, the el variable's 'background-image' property is changed to bg (ie xyz.jpg). Thus, the background-image has changed.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.