Lightning Web Components: Exploring the Contrast Between event.target and event.currentTarget

Lightning Web Components: Exploring the Contrast Between event.target and event.currentTarget

event. currentTarget tells us on which element the event was attached to or the element whose eventListener triggered the event.

event. target tells where the event started.

Understanding the distinction between these two is very important in effective Event handling in LWC. The below example will make it clear.

testEventTarget.html

testEventTarget.js

Click

Example 1: The triggering element and the element to which the event listener is connected are distinct.

Click

Example 2: The element responsible for triggering the event and the element hosting the event listener are one and the same.

Output

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics