How can I create a "ready-made" jQuery event handler after all the others?

I am working on a Greasemonkey script that will actually update the version of jQuery used on the page. To do this, I need to add a โ€œready-madeโ€ event handler that will run after all the others that may be on the page.

I know that jQuery expects the DOM to be manipulated before calling ready-made event handlers, so is there any way to influence the order in which they are executed? Thanks,

+4
source share
3 answers

They are called in the order in which they are registered. So, from the top of the page to the bottom. If you need this to be the last registered ready callback register, it is at the very end of the body tag. Also use $(window).load , not $(document).ready .

+3
source

Ready handlers are added to the readyList Array, which I'm sure is confidential, so I don't think you can directly influence it.

You might want to add code to readyList , but put it in setTimeout() so that it readyList little. Hope everyone else will be done first.

However, upgrading jQuery may cause problems. For example, there may be differences in the implementation of jQuery.cache , which stores event handlers and other data.

So, if jQuery.cache was populated with one version, it may not be compatible with another.

+3
source

How to control the order of functions called in jQuery $ (document) .ready

According to the answers to the question above, they should shoot in the order in which they are added (ajax calls in this particular question add more dirt to the water than to your question).

+1
source

Source: https://habr.com/ru/post/1334984/


All Articles