Skip to content

Instantly share code, notes, and snippets.

@io41
Created September 17, 2013 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save io41/6592046 to your computer and use it in GitHub Desktop.
Save io41/6592046 to your computer and use it in GitHub Desktop.
Track dom element clicks. Tested on chrome.
var getPath = function(el) {
var path = elName = "";
var siblings, siblingId;
while(el && elName != "body") {
elName = el.nodeName.toLowerCase();
siblings = (el.parentNode)?el.parentNode.childNodes:[];
siblingId = 0;
for (var i = 0; i < siblings.length; i++) {
if (siblings[i] == el) {
break;
} else if (siblings[i].nodeName.toLowerCase() == elName) {
siblingId++;
}
}
path = elName + ":eq(" + siblingId + ")" + ((path)?' > ' + path:'');
el = el.parentNode;
}
return path;
};
dojo.query(document).onclick(function(e){window.__clicks = window.__clicks || []; window.__clicks.push(getPath(e.target));});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment