<style>
#myblock>div {
width:30%;
height: 50px;
border: 2px solid #000;
margin: 5px;
display: inline-block;
}
.active {
background-color: red;
}
</style>
</head>
<body>
<div id="myblock">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<script>
var el, target;
myblock.onclick = function (e) {
e = e || window.event;
target = e.target || e.srcElement;
if (target.id =="myblock") return;
el && (el.className = '');
target.className = 'active';
el = target;
}
</script>
</body>