2

Currently I have this to create a Custom event in the JS code in my HTML document.

if (window.CustomEvent) {
  var event = new CustomEvent('not-loaded', {detail: {some: 'data'}});
} else {
  var event = document.createEvent('CustomEvent');
  event.initCustomEvent('not-loaded', true, true, {some: 'data'});
}
this.el.dispatchEvent(event); 

So how would I trigger a function in one of my HTML documents based on when this trigger is activated?

Travis J
  • 81,153
  • 41
  • 202
  • 273
Pallinator
  • 33
  • 4
  • 3
    Just like any other event handler? `someElement.addEventListener('not-loaded', function() { ... });` – Felix Kling Aug 12 '14 at 17:41
  • @FelixKling Which element would I use because I only have div elements in the HTML (long explanation)? – Pallinator Aug 12 '14 at 17:50
  • 2
    Again, just like with built-in events, you'd bind the handler to the element you want to listen on for the event, or to one of its ancestors. E.g. if I want to perform something when ` – Felix Kling Aug 12 '14 at 17:51
  • 1
    Given your example in the question you'd bind it to either `this.el` or any of its ancestors. – Felix Kling Aug 12 '14 at 17:57

0 Answers0