on Wed, modify Hangman game to use createElement stuff? http://alistapart.com/articles/behavioralseparation http://adactio.com/atmedia2005/ awful! my page bad. my page little better my page best! my page function doPopups() { if (!document.getElementsByTagName) return false; var links = document.getElementsByTagName("a"); for (var i=0; i < links.length; i++) { if (links[i].className.match("popup")) { links[i].onclick = function() { window.open(this.href); return false; } } } } window.onload = doPopups; inline (bad)
class-itis (bad)
unobtrusive (good!!)
Get all the links in the "imagegallery" element
CSS
#imagegallery a {
...
}
DOM
document.getElementById("imagegallery").getElementsByTagName("a")
function prepareGallery() {
if (!document.getElementsByTagName) return false;
if (!document.getElementById) return false;
if (!document.getElementById("imagegallery")) return false;
var gallery = document.getElementById("imagegallery");
var links = gallery.getElementsByTagName("a");
for ( var i=0; i < links.length; i++) {
links[i].onclick = function() {
return showPic(this);
}
}
}
window.onload=prepareGallery;