Nice image swapping

Last modified date

Comments: 0

Here’s a nice, clean, and simply way to swap an image on a click of a link. You might use this if you have one large image a series of thumbnails, and when you click on the thumbnail you want to swap the large image.

This javascript will do that and you don’t even need any additional libraries!

It works by having an extra property in the html tags called ‘show’. This will tell the javascript what image you want to show when the link is clicked on. You also have an image with the id ‘swap’ so that the javascript knows what is the image to be replaced.

The javascript looks like this:


What you'll want to do is set your links to whatever page or script you would normally use if you didn't have javascript image swapping. That way if people don't have javascript or an old browser then they will still get a functioning site.

Some example HTML:



Nice a clean, but with image swapping and no additional libraries! Nice.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.