Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image swapping - one liner 1

Status
Not open for further replies.

Xaqte

IS-IT--Management
Oct 4, 2002
971
US
For those of you that use the prototype library, I created this nifty one liner that allows easy image swapping:

img = the id of the image that you want to swap
newimg = the new image to swap it out with
* new image must be located in the same directory as the original

Code:
 $(img).src = $(img).src.replace($A($(img).src.split("/")).pop(), newimg);

I hope this helps someone!

X
 
For those without prototype, this works, and has no restriction on the images being in the same folder:

Code:
document.getElementById('imgId').src = 'newImage.jpg';

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Don't I feel stupid! I do have the tendancy to go overboard!

Thanks Dan!

X
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top