Wednesday, December 2, 2009

Re: [jQuery] Ignoring click events in cells

Yes there is.
 
Query the event.target and do an if conditional like so:
 
$("tr").click(function(e) {
 // normalize e.target
 if (!e) var e = window.event;
 var tg = (window.event) ? e.srcElement : e.target;
 
   if ( tg.nodeName != "INPUT"  ) {    
      alert($(this).attr("id"));
   } else {
    //do something
   }
 });
Regards
Maurício
 
-----Mensagem Original-----
De: Andyk
Enviada em: quarta-feira, 2 de dezembro de 2009 18:44
Assunto: [jQuery] Ignoring click events in cells

I have a table, which contains some data aswell as a checkbox:

<tr id="14373">
 <td><input type="checkbox"/></td>
 <td>...</td>
 <td>...</td>
</tr>
Each row contains an id, and I want to call a function based on the
click event:

            $("tr").click(function() {
                alert($(this).attr("id"));
            });

However, checking/unchecking the checkbox in each row also triggers
the event. Is there anyway of preventing this?

No comments:

Post a Comment