Mbrouwer88 Mbrouwer88 - 4 months ago 11
HTML Question

javascript nested onclick

I have this code:

<td onclick="Test()">
<img src="test.jpg" onclick="Test2(); return false;"><br>
Rest of the cell with some text.
</td>


When I click the image, Test() is also fired because I am also clicking the table cell. How to provent this? If I click on the image, I want test2() to fire, if I click somewhere else in the table cell, test() should be fired.

Edit: Even with return false, Test() is still fired(testing in Chrome)!

Answer

Short answer:

<img src="test.jpg" onclick="Test2(); return false;">

Long answer:

Event Order - http://www.quirksmode.org/js/events_order.html

Comments