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

What does the "e" parameter located in the event listener do?

I somewhat understand that this "e" is holding the place for the event, but I want to know how it's being used in the constant "button". I declared the constant button to be e.target, but how am I able to use this e parameter when it's not a variable? Does the parameter stand for which button is being clicked? Thanks for the help!

1 Answer

First of all, "e" can be the parameter name, but it can be anything you want, like even, myEvent, or event. Second, "e" refers to the event being listened for, so e.target would be how you access the target of that event (Which element receives the event). This is useful if say you have an input field where people can type and submit text. You give each of these texts the same class, and when each is clicked, you want all the "a"s in the text to turn to "b"s (Random example). The only way you would be able to select one of these input fields is by class, and you wouldn't want all the "a"s in all the texts to turn to "b"s when you only clicked the one. This is where e.target comes in. It selects the specific element clicked so only it will change. Hope that helps!

Yes, that makes total sense! I thought it was something like that... but needed someone else spelling it out for me. Thanks so much!