Custom event in jQuery that isn’t bound to a DOM element?

You can trigger custom global events like this in jQuery:

jQuery.event.trigger('mycustomevent', [arg1, arg2, arg3]);

These will trigger for any element.

Since jQuery is built around DOM objects, you have to bind your events to DOM objects. You can probably find some way to bind events without an element too (you did), but that’s not a supported methodology.

As you wrote in your own answer, you can bind your event to a global DOM object if you don’t want to bind it to an individual page element:

$(document).bind('mycustomevent', function (e, arg1, arg2, arg3) { /* ... */ });

Leave a Comment