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) Responding to User Interaction The Event Object

Maxim Melnic
Maxim Melnic
4,178 Points

Wow, 6 minutes to explain such difficult things;((

document.addEventListener("click", (event) => { console.log(event.target); });

event what's this? where does this argument come from? what does he assign? When we use function argument, we always specify the contents of the argument!!!

Why everywhere we use tagName in lowerCase and when use target.tagName, work only in UpperCase?

1 Answer

Steven Parker
Steven Parker
231,269 Points

The event object always contains data about the event that has occurred, so it is variable from one listener call to the next. One of the most useful attributes is event.target, which contains a reference to the DOM element that intiated the event.

The capitalization of the tagname attribute of an element depends on the document type. For HTML, it always contains the tag name in upper case, this is a legacy from previous HTML specification versions. For more information, see the MDN page on tagname.

Maxim Melnic
Maxim Melnic
4,178 Points

Thanks! Also found the answer to my question in the following statement:

"The details of event browser writes to the "event object", which is PASSED TO THE HANDLER AS THE FIRST ARGUMENT"