JavaScript JavaScript and the DOM 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
203,215 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"