Make onclick handler ignore clicks on links

javascript, jquery, onclick

Solution

Check the event object to see if the target is an anchor tag then return true:

$("div").click(function(eventObject){

    if($(eventObject.target).is("a"))
        return true;

    //run your code
});

Problem

I have a custom onclick handler for a block element (set up through jQuery's .click() method). This block element can contain links. I'm fairly certain this is possible, so, how do I have the handler simply return if it was a link I clicked on (so that the link is visited without running my code)?

Original source

Related problems