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 JavaScript and the DOM (Retiring) Getting a Handle on the DOM A Simple Example

Understanding the click effect

We passed an argument 'click' and I assume it is a text and not the actual click . Which part of the code is responsible of listening to the click?

2 Answers

Stuart Wright
Stuart Wright
41,119 Points

The first argument we pass to the addEventListener() method is a string representing the name of the event type to listen out for. One of these events is called 'click', which indeed means that the user has clicked on our element.

Steven Parker
Steven Parker
231,008 Points

Yes, "click" is a text string that names the kind of event you want to listen to.

The second argument to addEventListener is an "anonymous function" that contains the code that will be performed when a click happens. The code that is responsible for actually detecting the click (and then calling the function) is internal to the JavaScript engine.