Jump to content

background image swap


kev wood

Recommended Posts

i need a function that will swap images on a page when an iframe is loaded onto it.  i have tried to do this my self and have tried a few different methods but all to no avail i am still stuck.  i have tried to do it using the following code but i had no joy could anyone show me where the code is wrong or point me in the direction of a good tutorial.

 

function changeImage() {
if (document.getElementById) {
document.getElementById("image").src="images/home_title.jpg";
}
else if (document.all) {
document.all["image"].src="images/home_title.jpg";
}
else if (document.layers) {
document.layers["image"].src="images/home_title.jpg";
}
} 

 

inside the body tag

 

onload="changeImage()"

 

the image that i am trying to swap is a background image from a table and the code for this is

 

 id="image" background="images/commissioning_title.jpg"

Link to comment
Share on other sites

<table id="image" style="background:url('images/commissioning_title.jpg');">

 

function changeImage() {
  if (document.getElementById) {
    document.getElementById("image").style.background = "url('images/home_title.jpg')";
  }else if (document.all) {
    document.all["image"].style.background = "url('images/home_title.jpg')";
  }else if (document.layers) {
    document.layers["image"].style.background = "url('images/home_title.jpg')";
  }
} 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.