Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript DOM Scripting By Example Editing and Filtering Names Filter Invitees Who Have Not Responded

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

1 Answer

Steven Parker
Steven Parker
230,995 Points

The event target is the element that created the event.

The browser doesn't care if it was an INPUT or 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.