Animal Fun Facts question about task 9

Hi, I have a question about .target at task9.
task guided using to get the name of the animal being clicked.
I don’t understand how .target work.
,target is for picking up variable on code?

Events are responses to certain triggers that occur in your browser’s DOM. For example, clicking a button or interactable element can trigger a “click” event.

We can listen to these events with event listeners, so that when that event happens, the event listener will be aware of it and we can do something in response to the event happening.

The .target property of an event is a reference to the object that triggered the event in response to an action. For example, if I make a button element and create an event listener to listen for when that button is clicked on, when the button is clicked, the .target of that event is the button itself.

In this case, would thus return the “alt” attribute on the target of the event, the img tag of the animal. Et voila, evaluates to the name of the animal, since that what was in the alt attribute.

1 Like

Thank you for your answer that makes me having understanding about Enentlistener.