Edit in JSFiddle

var all = document.getElementsByTagName('div');

function echo(e) {
  console.log(this); 
  this.style.backgroundColor = 'blue';
};

for (var i = 0; i < all.length; i++) {
  all[i].addEventListener('click', echo, false);
}
<div>BOX1</div>
<div>BOX2</div>
<div>BOX3</div>
<div>BOX4</div>
div {
    display: inline-block;
    width: 50px;
    height: 50px;
    
    margin: 5px;
    border: 1px solid black;
}