How does e.target works?
Hi everyone, I have one question about e.target. I cannot understand how it works. I mean, how the browser can recognize that we mean that e.target is "input"? Couldn't it be instead "li" or "another tag?? Is there a way to associate e.target to a specified tag? Thanks
Steven Parker171,242 Points
The event target is the element that created the event.
The browser doesn't care if it was an
LI or some other tag. But for your code to receive the event at all, you must have established an event listener on the target element or on an "ancestor" element. So you can associate the event target with a specific element by how you establish the listener(s).
In this video, for example, an event listener is added to the filter check box. So when that event occurs, we know that e.target will contain a reference to that check box element.