You are using event propagation. The event comes from the element that you clicked on, but then propagates to the DOM tree in the root (document). You can use the stopPropagation method to prevent this, or return false from the event handler function (to prevent the default behavior and ):
$("*").click(function(e){ e.preventDefault(); e.stopPropagation(); alert(this.tagName); });
or
$("*").click(function(e){ alert(this.tagName); return false;
Aside, $(this)[0] is nonsense. You create an array type object containing this , and then return the first element ( this ), so unnecessary function calls and access to the array get what you already have a direct reference to. Net overhead for zero gain, just use this directly.
source share