Assigning events to elements with same class name

Your code works.
I am now trying to follow your advice, but the following does not work:

document.getElementsByClassName('M').addEventListener('click',function (){
	alert("IT WORKS");
},false);