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 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
229,708 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.