gberger
gberger

Reputation: 2863

jQuery .on already fired event

If I do something like this after the DOM is loaded, the function still executes:

$(document).ready(fn)

However, the following does not execute the function if the 'myEvent' event has already been fired previously:

$(document).on('myEvent', fn)

Is there a jQuery solution, which does not require me to code my own event delegator, that fires previous events to a "late" event handler?

Upvotes: 0

Views: 148

Answers (1)

Matías Fidemraizer
Matías Fidemraizer

Reputation: 64933

Actually I believe you don't need that because that should point to a bad design decision.

Furthermore, it's fine getting ready event callback executed even if the document has already signaled that it's ready, because this event happens once per page life-cycle.

Just imagine that click event would allow you to do that you're requesting for but before adding the event handler the user clicked the target element more than once? Would setting the event handler invoke it twice or more times?

Upvotes: 3

Related Questions