Home > Mobile >  What is an event object?
What is an event object?

Time:10-01

Does it exist before an event is triggered or is it created by the event? For example when a click event is triggered is the click property added to some already existing event object? Or is an object for this event created when the event is triggered?

CodePudding user response:

It is created when a certain event is fired; you can then use it inside your event handler function.

Here is a compact example with jQuery, as requested:

$("#my-btn").click(e => {
  console.log("Here is the event object:");
  console.log(e);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>

<button id="my-btn">Click</button>
<i>Logging the object to the console may be slow as the event object is very large</i>

  • Related