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?
someElement.addEventListener('not-loaded', function() { ... });<button>is clicked, I bind the click handler to that button. If you are justing using custom events to pass messages and you actually don't need the DOM at all, something like github.com/mroderick/PubSubJS might be better suited.this.elor any of its ancestors.