I have a script that creates an element, and part of the creation process is to add an onclick event (using addEventListener), but when I click a child element, the onclick event of the parent is triggered. How can I prevent the click from being detected when the source is a child element?
Share
Use
event.stopPropagation(). This stops the bubbling of Javascript events and will only allow the events applied to the targetted element to execute;