I want to attach a click event at the document level with
$(document).click();
And on clicking the element i would like to find out whether it is an anchor tag. If it is an anchor tag, then i will call a method to do something. How can that be done? Any idea?
You’ll just have to check the event object’s target.
(cross-browser code for getting the event target from quirksmode)
Also, if you’re going to attach also other event handlers to the links, make sure you use
event.preventDefaultinstead of just returningfalseif you want to cancel the link’s default action (see this question).