How can I define a one-time event so that new handlers fire (once) even after the event has already occurred?
Posted
by
harpo
on Stack Overflow
See other posts from Stack Overflow
or by harpo
Published on 2013-07-02T04:44:32Z
Indexed on
2013/07/02
5:05 UTC
Read the original article
Hit count: 135
You know how this
$(function() { ... });
will fire whether or not the "document ready" event has already occurred? I want to define an event like that.
That event is a special case in jQuery. I'm wondering if a custom event can behave in the same way, using only the standard event mechanisms.
Ideally, I'd like to be able to define handlers in the "normal" way:
$(document).on("init.mything", function() { ... });
This works now if the above runs before init.mything
is triggered. But if it doesn't, then the handler never runs.
What makes this tricky is, I don't want to assume anything except that jQuery has loaded.
Any ideas?
© Stack Overflow or respective owner