How to trigger $().ready() in jQuery?

If you just need to make sure that new initialization functions get run, you don’t need to do anything. When you add a new event handler in $().ready, after the document finishes loading, it will run immediately.

Apparently, calling $().trigger("ready") directly doesn’t work because jQuery resets the ready event handlers after it runs them. You will need to keep track of the functions you need to call, and call them directly as below.

Of course, it might be better to just call the function directly, so you don’t re-run something you didn’t intend to (some plugins might have their own $().ready() functions that they don’t expect to run twice).

$().ready(initializationFunction);

// later:
initializationFunction(jQuery);

Leave a Comment