Zyuzka,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<script>
function test(){
var divs, old;
for(var j = 0; j < 6; j++) {
divs= document.getElementById('a' + j);
divs.onclick = function () {
old && (old.style.backgroundColor='')
this.style.backgroundColor = "blue";
old = this
}}}
</script>
</head>
<body onload="test()">
<div id="a0">1</div>
<div id="a1">2</div>
<div id="a2">3</div>
<div id="a3">4</div>
<div id="a4">5</div>
<div id="a5">6</div>
</body>
</html>