Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many document.ready in single html file or javascript file?

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?

like image 644
Miqdad Ali Avatar asked Nov 18 '25 12:11

Miqdad Ali


2 Answers

Well, I believe 'As much as you want'. But I would prefer to keep my code neat.

like image 132
Akhil Sekharan Avatar answered Nov 20 '25 03:11

Akhil Sekharan


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.

like image 38
Curtis Avatar answered Nov 20 '25 03:11

Curtis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!