Skip to content
Advertisement

Separate onClick event for parent and child element

I have JSX code like this:

JavaScript

When I click on parent (outside the child) it will run clickOnParent, and when I click the child it will run both clickOnParent and clickOnChild of course.
Now I want to trigger only clickOnChild and ignore clickOnParent when clicking exactly on the child. How can I do?

Advertisement

Answer

Use Event.stopPropagation()

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement