+ 7

How to prevent parents onclick event when its child is clicked?

In the example below, I have a div element which contains button element. When i click on the div, divFunction() is called, but when i click on the button, buttonFunction() AND divFunction() are called. How do I prevent this, if I want only buttonFuction() to be called when i click on the button. I think, this problem has some elegant solutions using jQuery, but i havent started learning jQuery yet, so i would rather use only pure JavaScript. https://code.sololearn.com/WJUKzE09HwIG/?ref=app

23rd Aug 2020, 11:08 PM
Atom
Atom - avatar
2 ответов
+ 10
https://code.sololearn.com/W5iATFX0sZ8N/?ref=app
23rd Aug 2020, 11:12 PM
Kevin ★
+ 5
Thanks a lot.
23rd Aug 2020, 11:15 PM
Atom
Atom - avatar