views:

57

answers:

2

Hi everyone,

I am using jquery to implement event delegation on my page. I define a click handler for the top level element, but only want to do something "custom" if the click fell on an element of certain class:

$("#myDivWithManyLinks").click(function(e){
   var target = $(e.target);
   if (target.hasClass('myClass123')
   {
       // do my "custom thing"
       return false;
   }
   else
   {
       // XXX let the click be handled by the click handler that would otherwise get it
   }

How can I do "XXX"?

Thank you for any help,

lara

A: 

write a handler function and then reference it in else:

   $("#myDivWithManyLinks").click(function(e){
    var target = $(e.target);
    if (target.hasClass('myClass123')
    {
       // do my "custom thing"
       return false;
    }
    else
    {
       handler(e);
    }
   });
   function handler(e){
      // what you want all links that don't have your special class to do
   }
Sarah Jean
A: 

what about preventDefault():

$("#myDivWithManyLinks").click(function(e){
    var target = $(e.target);
    if (target.hasClass('myClass123')
    {
       e.preventDefault();
       //do custom stuff
    }

   });
easement