I want to track ALL elements that are clicked on a HTML-page. I need a good way to reference exactly which element was clicked (so I will be able to replay the clicks on a identical separate HTML-page later on).
Is there a good way to reference which element that was clicked?
I could add unique id's and classnames to every single element on the page. But I figure there must be another way?
The HTML-page which I will be replaying the clicks on will be identical.
Something like this (but more exact information which element it was, maybe that's possible to collect)...
Code to track which element was clicked
var arrayWithElements = new Array();
document.onclick = clickListener;
function clickListener(e) {
var clickedElement;
if(e == null) {
clickedElement = event.srcElement;
} else {
clickedElement = e.target;
}
arrayWithElements.push(clickedElement)
alert(arrayWithElements);
}
Code that will be used on a identical HTML-page
document.someHowGetTheElement().onclick();