# The Best Way to Implement Tooltips in the Modern Era

# The Best Way to Implement Tooltips in the Modern Era Published on Tuesday, September 15, 2026, at 10:38, under JS Examples. by zhangxinxu from https://www.zhangxinxu.com/wordpress/?p=12403 This article may be republished in full, provided that the original author, source, and ...

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.