Reputation: 1330
here is my issue:
I have an img with an onclick handler inside a div that also has an onclick handler.
<div onclick="someFunction();">
<img src="/Images/SomeImage.png" onclick="someOtherFunction();" />
</div>
When clicking on the image, I don't want the div's handler to be fired.
I have tried adding "return false;" at the end of my img's onclick, to no avail.
The reason I need it done that way is because I have a bunch of projects, hovering the div highlights that entry and if you click on it that'll show you more details, but you might also want to edit/delete that entry.
Thanks !!
Upvotes: 0
Views: 1421
Reputation: 6349
Use the stopImmediatePropagation()
method to stop the immidiate propagation.
HTML
<img src="/Images/SomeImage.png" onclick="someOtherFunction(event);" />
javaScript
//this function stops the propagation and not triggered parent div's handler
function someOtherFunction(event) {
event.stopImmediatePropagation();
return false;
}
Upvotes: 2