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
https://forums.phpfreaks.com/topic/103379-background-image-swap/
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')";
  }
} 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.