<style>
* {margin:0;padding:0}
.green {background-color:#77FC79}
.red {background-color:#FA4B57}
div.block {
margin: 30px;
border:1px #2E2E2E solid;
text-align:center;
padding:10px 0px;
width:100px;
}
.left {
position:absolute;
left: 150px;
}
</style>
<div class="left">
Clicked : <b id="res">0</b>
</div>
<div class="block red">hello</div>
<div class="block red">hello</div>
<div class="block red">hello</div>
<script>
window.onload = function(){
var a = document.getElementById("res");
document.body.onclick = function(e){
var el = e ? e.target:event.srcElement;
var cls = el.className;
if(!~cls.indexOf("block")) return;
if(~cls.indexOf("green")) {
el.className = "block red";
a.innerHTML--;
} else {
el.className = "block green";
a.innerHTML++;
}
}
}
</script>