Home › Forums › CSS › Change Main Background Image › Re: Change Main Background Image
April 25, 2009 at 6:49 pm
#56735
AshtonSanders
Participant
Hi Niplo,
Good question. Basically, you will use CSS to assign the background like normal, and then use Javascript to change the background image.
Here’s the basic Javascript code for changing an element’s background:
Code:
document.getElementById(‘randomID’).style.backgroundImage = “url(images/myimage.gif)”;
Then you could use a "onclick" attribute to run the code. Simple example:
Code:
Note: that you will need to replace randomID with the ID of the item you will be replacing. You may need to give an ID to <body> if that is where you background is applied to.
-Ashton Sanders
-www.WebssitesinaFlash.com