Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens if more than one user control registers $(document).ready function?

I have a couple of user controls in an aspx page. And each user control may need to register a start-up block as an $(document).ready() function event handler.

Do they override each previous functions of they are chained in order of registration?

like image 426
pencilCake Avatar asked Mar 11 '11 09:03

pencilCake


People also ask

Can we use multiple document ready () function on the same file?

Can we add more than one 'document. ready' function in a page? Yes we can do it as like I did in below example both the $(document).

What does $( document .ready function () do?

$( document ).ready()A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.

Can I have 2 document ready function?

We can have multiple document. ready() function in our code but only one body. onload() is allowed.

Can we use multiple document ready function in jQuery?

Multiple $(document). It's great to be able to group your functions within a file or even across multiple files, and jQuery's flexible $(document). ready() function allows you to do that, pain free.


1 Answers

They are just added as event handlers to the documents 'ready' event (an abstracted event provided by JQuery).

In JQuery event handlers are executed in the order they were bound.

Eventhandlers are not chained - as that would mean handler#3 would not fire if handler#2 failed to execute successfully. They are simply executed by the event manager in turn.

like image 109
Sean Kinsey Avatar answered Sep 18 '22 18:09

Sean Kinsey