I have the following html code:
<div class="outerElement">
<div class="text">
Lorem ipsum dolar sit amet
</div>
<div class="attachment">
<!-- Image from youtube video here -->
</div>
</div>
And I have a jQuery onclick event on the .outerElement however, I don’t want the .outerElement onclick event to be called when I click on the attachment, is there some way to prevent this or to check which element is clicked?
Use
event.stopPropagation()on the child element.This prevents the event from bubbling up the DOM to the parent node.
Also part of the
eventobject is thetargetmember. This will tell you which element triggered the event to begin with. However, in this instance,stopPropagationappears to be the best solution.