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
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")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.
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.thank you all for the answer guys.
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