Clicking on elements in jQuery causes bubble up to body. If we have a click handler binded to body that shows an alert, then clicking on any element will bubble up to body and trigger the alert. My Question is, is there any way to know if the body alert was triggered as a result of direct click to body, or was the click triggered because of a bubble up to body.
Share
Compare
event.targettothis.thisis always the event where the handler is bound;event.targetis always the element where the event originated.In the case of elements you know to be unique in a document (basically, just
body) you can also check thenodeNameofthis:You have to do
toLowerCase()because the case ofnodeNameis inconsistent across browsers.One last option is to compare to an ID if your element has one, because these also have to be unique: