How many $(document).ready() function can we use in a single html file or in a single javascript file?
$(document).ready(function(){
alert("first document ready");
//do some action here
});
$(document).ready(function(){
alert("second document ready");
//do some action here too
});
If we can use infinite, how will they be invoked? Will they execute line by line or is there any algorithm for calling this?
Well, I believe 'As much as you want'. But I would prefer to keep my code neat.
There is no limit to some extent (until performance becomes an issue). They are just event listeners for when the document is ready.
Its not the same as say Page_Load event in ASP.NET C#
I generally limit to one "document ready" function per javascript file however, for organisation purposes.
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