Click an element in your HTML tree and a note climbs from e.target to the teacher, the listener: read e.target, e.currentTarget or this now, later in a…
This is the heart of event delegation: one listener on a parent handles many children, including ones added later. Pick the wrong one of target/currentTarget, or use this in an arrow function, and the handler changes the wrong element or throws.
target = what was clicked, currentTarget = where the listener is
target when you want the element with the listener target can be the deepest child (an icon or a <span> inside the button). Use e.currentTarget, or e.target.closest(sel) for delegation.this inside an arrow function handler An arrow function has no this of its own, so it is not the element. Use e.currentTarget so it is right in both forms.e.target directly in delegation A click can land on a child of the item. Use e.target.closest('.item') to climb to the item you mean, and check it is not null.e.currentTarget becomes null in a setTimeout or after await The browser clears currentTarget as soon as dispatch is over. Save it to a variable at the start of the handler.e.target = <b>, e.currentTarget = <ul>. The board writes the path between them.<li> or a <button> currentTarget moves with it. target stays what you clicked.e.target.closest('li'), click the bold text From <b> up to <li>: the row gets marked, not the word.e.currentTarget in a setTimeout Pick "in a setTimeout" with e.currentTarget, then click. It is null and classList throws a TypeError.