Last active
December 30, 2015 17:19
-
-
Save jtoll/7860345 to your computer and use it in GitHub Desktop.
A simple example of a javascript function to swap thumbnail images on click
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Title | index.html</title> | |
<script> | |
function showImg(x) { | |
document.getElementById("target").src=x.src; | |
} | |
</script> | |
</head> | |
<body> | |
<div> | |
<img id="target" width="200" height="200" alt="Image"/> | |
<div> | |
<a href="#target"><img src="holder.js/50x50/#D40000:#FFF/text: " width="50" height="50" alt="Color 1" onload="showImg(this)" onclick="showImg(this)"/></a> | |
</div> | |
<div> | |
<a href="#target"><img src="holder.js/50x50/#2F7888:#FFF/text: " width="50" height="50" alt="Color 2" onclick="showImg(this)"/></a> | |
</div> | |
<div> | |
<a href="#target"><img src="holder.js/50x50/#FF7900:#FFF/text: " width="50" height="50" alt="Color 3" onclick="showImg(this)"/></a> | |
</div> | |
<div> | |
<a href="#target"><img src="holder.js/50x50/#399827:#FFF/text: " width="50" height="50" alt="Color 4" onclick="showImg(this)"/></a> | |
</div> | |
<div> | |
<a href="#target"><img src="holder.js/50x50/#651568:#FFF/text: " width="50" height="50" alt="Color 5" onclick="showImg(this)"/></a> | |
</div> | |
<div> | |
<a href="#target"><img src="holder.js/50x50/#FF0:#FFF/text: " width="50" height="50" alt="Color 6" onclick="showImg(this)"/></a> | |
</div> | |
</div> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/holder/2.0/holder.min.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment