2

I don't unterstand this:

I try to create a custom event which should be fired when a list is fully loaded in a table body. Like this (executes after list is loaded):

  var event = new Event('mklistloaded', {
        name: 'listname'
  });

  document.dispatchEvent(event);

And this is the "receiving" end:

document.addEventListener('mklistloaded', function(e) {

    console.log('mklistloaded event: ' + JSON.stringify(e));

});

But console log prints out:

mklistloaded event: {"isTrusted":false}

That's quite the same as described in the mozilla example:

https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events

What am I doing wrong here?

0

1 Answer 1

1

You missed the section in the docs "Adding custom data – CustomEvent()"

document.addEventListener('mklistloaded', function(e) {
  console.log('mklistloaded detail: ', e.detail);
});
// use CustomEvent() instead of Event()
var event = new CustomEvent('mklistloaded', {
  'detail': 'listname'
});

document.dispatchEvent(event);

Note that it seems to require using the property name detail

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.