javascript get event before stop code example

Example 1: onclick stoppropagation

<span onclick="event.stopPropagation(); alert('you clicked inside the header');">something inside the header</span>

Example 2: how to prevent event capturing in javascript

how to prevent event button click capturing to tag/div/icon
easiest way OPTION 1 with CSS:
button > * {
  pointer-events: none;
}

OPTION 2 with javascript:
use e.currentTarget.children ;

OPTION 3 with Javascript:
use e.target.closest('selector') to locate the child, not e.currentTarget;

Tags:

Misc Example