window.onload = function () { var aspan = document.getElementsByTagName("span"); var i = 0; for (i = 0; i < aspan.length; i++) { aspan[i].onclick = function () { for (i = 0; i < aspan.length; i++) aspan[i].className = ""; this.className = "curr"; }; } };