Pechen,
<!DOCTYPE HTML>
<html>
<head></head>
<body>
<div class="a">Div 1</div>
<div class="a">Div 2</div>
<div class="a">Div 3</div>
<div class="a">Div 4</div>
<div class="a">Div 5</div>
<script>
for (var elem = document.getElementsByTagName("div"), a = 0, i = 0; i < elem.length; i++) {
var option = elem[i].className;
"a" == option && (elem[i].onclick = function(b) {
return function() {
alert(b)
}
}(a++))
};
</script>
</body>
</html>