What are the scenarios we really need to use custom event in javascript?

Because i’m trying to learn custom event but i am not getting any practical example?

Primarily custom events are most useful to help programmers more clearly understand what’s going on.

yeah but will u give me a simple example to understand better

Sure thing.

var event = new CustomEvent('build', { detail: elem.dataset.time });


function eventHandler(e) {
  console.log('The time is: ' + e.detail);

Hmm u have created a custom event build alright but when there will be a need to implement this in code…

That time might be when a Build button is clicked.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.