If I append a child element to a parent element, is it possible to stop the propagation of the parent's event to the appended child if I don't have access to the parent element's event listener code? If it's even possible, how?
Is there a way to do this inside the child event listener? Is there something like e.target.parentElement.stopPropagation()
?
If the event passes through the child you appended, you can stop it by calling
stopPropagation
on it. It has nothing to do with what element's handler does that; all that matters is that one of them calls that method on the event. So juste.stopPropagation()
.If the event doesn't pass through the child (it's directly targeted at the parent, or passes through some other child to the parent), you can't stop propagation of it unless you can attach your handler to the parent element before the other handler is attached. But from your description, it doesn't sound like you can do that.