Something like that. You will add interactive links to the array, and then attach the click event to the document, in the event method you will get the goal to click the mouse, if any, and at what position in the array.
window.onload = function() { var clickableLinks = []; var links = document.getElementsByTagName("a"); for(var i=0,len=links.length;i< len;i++) { var link = links[i]; if(link.className.split(" ").indexOf("a") != -1) { // Or another detection clickableLinks[clickableLinks.length] = link; } } document.attachEvent('onclick', clicked); // IE document.addEventListener('click', clicked, false); // Other browsers function clicked(event) { var target; if (event.target) {target = event.target}; if (event.srcElement) {target = event.srcElement}; var index = clickableLinks.indexOf(target); if(index != -1) { alert("clicked at", index+1, "link"); } }
Schovi
source share