Ideally, we'd just give the image an ID, and reference its src by that. However, as it stands...
Code:
<script type="text/javascript">
function imageChange(div, path) {
var m = document.images;
// Iterate through m, checking the parent of every image and seeing if it matches div.
// If so, change its src to path.
for(var i=0;;i++)
if(m[i].parentNode === div)
m[i].src = path;
}
</script>
<a href="javascript:void(0);" onclick="imageChange(document.getElementById('imagecontainer'), 'red.jpg')">Red</a>
Bookmarks