Topic: Changing a <div> background image?

Hi guys,

How would I go about changing the background image of a <div> tag using clickable links that will appear on my site. The following example allows me to change the whole page background, but I need it to only change the background image set within a <div> tag. Does that make sense?

http://www.codebelly.com/javascript/bac … hange.html

I hope someone can help me out,
thanks,
Will

2 (edited by Bodram 2006-11-28 12:45)

Re: Changing a <div> background image?

Something like:

<a href="#" onclick="document.getElementById('MyDiv').style.backgroundImage='url(bg1.png)'">Show 1</a>
<a href="#" onclick="document.getElementById('MyDiv').style.backgroundImage='url(bg2.png)'">Show 2</a>
<div id="MyDiv">
    text here
</div>

Edit: maybe read up on the html dom ? http://www.w3schools.com/htmldom/dom_obj_style.asp

Re: Changing a <div> background image?

Thank you very much Bodram smile Worked a treat.