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 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
210,070 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"