var myVar = document.getElementsByClassName('a');
myVar[0].parentNode.addEventListener('click', function(e) {
var self = e.target;
if(self.className != 'a') return;
var i = myVar.length;
while(i--) {
if(myVar[i] == self) {
var x = i;
break;
}
}
alert(x);
});