1function clickOrigin(e){
2 var target = e.target;
3 var tag = [];
4 tag.tagType = target.tagName.toLowerCase();
5 tag.tagClass = target.className.split(' ');
6 tag.id = target.id;
7 tag.parent = target.parentNode.tagName.toLowerCase();
8
9 return tag;
10}
11
12var tagsToIdentify = ['img','a'];
13
14document.body.onclick = function(e){
15 elem = clickOrigin(e);
16
17 for (i=0;i<tagsToIdentify.length;i++){
18 if (elem.tagType == tagsToIdentify[i] && elem.parent == 'a'){
19 console.log('You\'ve clicked a monitored tag (' + elem.tagType + ', in this case and one inside an "a" element, no less!).');
20 return false; // or do something else.
21 }
22 else if (elem.tagType == tagsToIdentify[i]){
23 console.log('You\'ve clicked a monitored tag (' + elem.tagType + ', in this case).');
24 return false; // or do something else.
25 }
26 }
27};
28