/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>blubb</title> </head> <body> <div id="PageHeader"> </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"> </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>