I have the following JavaScript:
<div>
<tr onClick="click1()">
<td>
click 1
</td>
<td onClick="click2()">
click 2
</td>
</tr>
</div>
function click1() {
alert(1);
}
function click2() {
alert(2);
}
<table border="1">
<tr onClick="click1()">
<td>
click 1
</td>
<td onClick="click2()">
click 2
</td>
</tr>
</table>
If I click 'click 1', the click1() function is called as expected. If I click 'click 2', the click1() & click2() functions are both called.
Question
How do I make the click on 'click 2' only call the click2() function, and not call the click1() function?
onClickattribute into thetdtag of click 1event.stopPropagation();in your click2 function.click1(). However, if they click on a specific item in the row it calls functionclick2().