Click on <tr>, but only if clicked <td> is not an <a>

html-table, jquery

Solution

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

Problem

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?

Original source

Related problems