Is there an event that I can register that will be executed after all $(document).ready
scripts are executed? I've got a piece of code that needs to be executed after the whole page is fully loaded (also the jQuery scripts). Is this possible?
I need to register this in a script file, so can't put the function at the bottom of the page.
So, there is no event called after document. ready(). You'll need to create and wait for events to complete on your own, or use window. load().
on( "ready", handler ) , deprecated as of jQuery 1.8 and removed in jQuery 3.0.
The jQuery document ready function executes when the DOM (Document Object Model) is completely loaded in the browser. jQuery document ready is used to initialize jQuery/JavaScript code after the DOM is ready, and is used most times when working with jQuery. The Javascript/jQuery code inside the $(document).
The document. ready() function will be executed as soon as the DOM is loaded. It will not wait for the resources like images, scripts, objects, iframes, etc to get loaded.
It is not possible to attach an event to when all of the scripts are executed and run. There is no hook for for your particular case in javascript because scripts can have very different logic like being loaded asynchronously, having timeouts, etc. But there is an event that is fired when all of the scripts are loaded in the browser (but still they are not executed):
$(window).load(function () {
// your code is here
});
will be executed after the whole page including scripts and graphics will be loaded. Though, this doesn't mean the scripts are actually executed. But, if your scripts only contain the logic that requires immediate actions like
alert('Hi!');
then those will be executed before $(window).load()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With