# A Handy Tip for Passing Parameters with JS CustomEvent

# A Handy Tip for Passing Parameters with JS CustomEvent Passing parameters with custom events is mainly done through `CustomEvent.detail`. ## 1. Triggering an Event Bound with addEventListener For example, suppose an `'input'` event is bound to an input element, and the DOM obj...

Code: Dispatching a CustomEvent

const event = new CustomEvent('show', {
  detail: { message: payload, sentAt: new Date().toLocaleTimeString() }
});

window.dispatchEvent(event);
Result
Waiting for an event...

Code: Listening for the Event Payload

window.addEventListener('show', (event) => {
  render(event.detail.message, event.detail.sentAt);
});
Event log
No events yet.