<html>
<head>
</head>
<body>
<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>
<script>
divs=document.querySelectorAll("div")
f=function () {
var n=(+this.id[1])
;[].forEach.call(divs, function(div){div.style.background=(+div.id[1]<=n) ? "blue" : ""})
}
;[].forEach.call(divs, function(div){div.onclick=f})
</script>
</body>
</html>