Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change image by day (background)

Status
Not open for further replies.

Mike12tet

Technical User
Dec 15, 2003
24
0
0
NZ
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.

Michal
 
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.

Thanks

 
Well, I'm not the best expert on Javascript, but here's the important parts:
Code:
var el=document.getElementById('midimage');
...
<div id="midimage">&nbsp;</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 &nbsp;.

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.

Hope that is helpful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top