Code:
function toggle(obj) {
re = /first_image.jpg$/
if(obj.src.match(re)) {
obj.src = 'second_image.jpg';
}
else {
obj.src = 'first_image.jpg';
}
}
This code takes an image object, searches the image source for the name of the file and changes it to the appropriate one.
Code:
//the toggle function
function toggle(obj) { //pass the img object to the function
//create a 'regular expression' to search for the filename. The $ means it will search the end of the string
re = /first_image.jpg$/
//test for a match
if(obj.src.match(re)) {
//if it matches use the second image
obj.src = 'second_image.jpg';
}
else {
//if it does not match use the first image
obj.src = 'first_image.jpg';
}
}
//Remember to include the file extension (.gif .jpg)
Bookmarks