3

I have a table with structure like this :

 <table>
 <tr id="ui-id-7" onclick="editThis();">
 <td>100</td>
 <td>Test</td>
 <td class="noEdit"><a href="www.mysite.com" target="_blank"><img src="www.mysite.com/test.jpg"></a></td>
 </tr>
 </table>

What I need : the entire <tr> is clickable and calls the editThis() method, UNLESS if the user clicks on the <td> that has the link element (in case, the one with noEdit class).

In the code above, clicking on ANY <td> (or the <tr>) will call the editThis() method. I know I could write the call for each <td> instead of the <tr>, but this would be a lot of writing...

Is this possible?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
delphirules
  • 6,443
  • 17
  • 59
  • 108
  • http://stackoverflow.com/questions/9012537/how-to-get-the-element-clicked-for-the-whole-document – Martijn Feb 20 '14 at 17:41

1 Answers1

7

Use event.stopPropagation()

$('#ui-id-7 td.noEdit').click(function(e){
   e.stopPropagation();
});

Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107