Return to Snippet

Revision: 22183
at January 5, 2010 03:40 by shapeshifta


Initial Code
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>blubb</title>
</head>
<body>
	<div id="PageHeader">&nbsp;</div>
	<div id="PageContent">	
		<img class="thumb" src="http://snipplr.com/bookcovers/bookjs1.jpg" alt="" />
		<img class="thumb" src="http://snipplr.com/bookcovers/book-django.jpg" alt="" />
		<img id="main_image" src="" alt="" />
	</div>
	<div id="PageFooter">
		&nbsp;
	</div>

<script type="text/javascript">
// see http://snipplr.com/view/2950/getelementsbyclassname/
// Implementation of the missing (nonexistant) 'document.getElementsByClassName()
document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
return retnode;
};

function start(){
	var thumbs = document.getElementsByClassName('thumb');
	for (var i = 0; i < thumbs.length; i++) {
		thumbs[i].onmouseover = function(){
			document.getElementById('main_image').src = this.src;
		}
	}

	
}

window.onload = start;
</script>
</body>
</html>

Initial URL

                                

Initial Description

                                

Initial Title
Change other image on mouseover

Initial Tags
js

Initial Language
JavaScript