Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM Responding to User Interaction The Event Object

event.target question

I am still not 100% clear on the use of event.target for targeting specific elements. I think it's because I just need more practice. Before he introduced event.target, I thought the handlers worked fine when you moused over and moused away from the list items. Could somebody provide some other examples of using event.target?

Where can we get more practice with event handlers and even.target?


1 Answer

Steven Parker
Steven Parker
208,481 Points

:point_right: The establishment of event.target is unrelated to the type of event.

There are a wide variety of actions that can cause events to occur, such as a mouse over, mouse out (away), button click, drag, scroll, etc. All events pass an event object to the handler, which contains a number of properties including the target which is the element to which the event was originally dispatched. This is particularly useful when you have attached the same handler to more than one element.

Using one of the existing exercises or projects as an example, you might try experimenting with responding to other types of events and/or responding in other ways. See the MDN Event reference for a list of other events.