question regarding events in this example

Hello guys I am new at learning js and I am struggling with events a little bit, for example here in this example: const buttonContainer = document.querySelector(".button-container"); buttonContainer.addEventListener("click", function (event) // what is event here inside of the parenthesis { alert(You clicked on button ${event.target.innerText}) });
5 Replies
ἔρως
ἔρως4w ago
event is an instance of PointerEvent, as explained here: https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event if you mean from a syntax level, event is a function argument (or just "argument")
Choo♚𝕂𝕚𝕟𝕘
That is the name of the parameter for the callback function. The value passed to it is an event object. The specific properties of the event object depends on the type of event that you are listening for.
clevermissfox
clevermissfox4w ago
Id recommend console.log(event) inside your event listener and take a look to get an idea of all the methods natively available to it.
theboyduddus
theboyduddus4w ago
thank you all for the answer guys.
b1mind
b1mind4w ago
Just a heads up you might need to use console.dir(event) in chrome. FF does it auto magically #depends what the object is but I just default to .dir() in chrome
Want results from more Discord servers?
Add your server