I have a click bound as live to an element. The handler returns false after execution, but if the element happens to be an A tag, then the link is also not followed, which is unacceptable...
$('*').live('click', function(){
// lots of code here
return false;
});
Now if the element that is clicked on has a path like A>img
and the image is clicked on, the A will never be followed. I dont want the click event to propagate any further.
how do I achieve this?
Edit:
It is essential for my application to bind the event to *. Also, the clicks can be made on any element, not just A's. Thus none of the mentioned solutions are suitable for what I wish to achieve.
I would not bind a click function to *
. You could bind it to the body
element; the click will propagate from the element that was clicked to the body
element. You can check the element that was originally clicked like this:
$("body").live("click", function (e) {
if ($(e.originalEvent.target).is("a")) {
return false;
}
});
Having said that, you can still do this:
$("*").live("click", function () {
if ($(this).is("a") == false) {
return false;
}
});