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 DOM Scripting By Example Editing and Filtering Names States of the Application

further explanation of the use of the e.target.

Hi. I generally know the use of the e.target, we use it to select the specific element clicked, but i still dont fully understand this term.. I know when we want to remove or add a list item element for example, we first get a ref to the specified html element that we clicked on with a simple if statement.

anyone can explain it better?

1 Answer

Steven Parker
Steven Parker
218,654 Points

It depends on what the handler is intended to do. For example, if clicking on a button changes the color of the page main title, then the handler will have no need for the event object (or the "target" attribute).

But if the handler does something relative to the item clicked, then the event target gives you a starting point to perform the DOM traversal with. Whether a condition ("if") would be involved is another matter. For example, if you wanted clicking on a paragraph to change its font to bold, you would not need "if", but you would use the event target to set the font weight.