Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set onClick on the tr except for his second td

<tr class="DesignedTableTR" onclick="OpenAdPreview()">
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>

I want that the onclick will be set on all the td-s except for the second td.

I know I can do it like:

<tr class="DesignedTableTR">
    <td onclick="OpenAdPreview()"></td>
    <td></td>
    <td onclick="OpenAdPreview()"></td>
    <td onclick="OpenAdPreview()"></td>
</tr>

but maybe there is another efficient way..

like image 992
Alon Shmiel Avatar asked Sep 08 '13 11:09

Alon Shmiel


2 Answers

Another way for doing

<tr class="DesignedTableTR" onclick="OpenAdPreview()">
<td></td>
<td onclick="event.cancelBubble=true; return false;"></td>
<td></td>
<td></td>

like image 135
s k Avatar answered Sep 16 '22 22:09

s k


Use the :not() and :nth-child() selectors.

$("tr.DesignedTableTR > td:not(:nth-child(2))").on("click", OpenAdPreview);
like image 40
Itay Avatar answered Sep 18 '22 22:09

Itay