var titles = document.querySelectorAll('.titles'); titles.forEach((el,i)=>el.addEventListener('click',function(){ console.log(i,el); }));