Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fire something after $(document).ready() completes?

Is there a way to have your function be called as the LAST in the $(document).ready() queue or, is there a way to trigger an event once this has completed?

I want to essentially see if something was fired by $(document).ready() and, if not, fire it after wards. If I put this code into document ready then there is no guarantee it will execute last so could result in multiple checks.

like image 915
Chris Avatar asked Dec 18 '25 16:12

Chris


1 Answers

You can set a global variable when your function is fired, and check that before running it again:

E.g.,

function myFunc()
{
    if (myFuncHasFired)
        return;
    myFuncHasFired = true;
    //your func code here
}

This does not guarantee your function will run last, but satisfies what I think is your real requirement that the function not run multiple times in one request.

like image 99
D'Arcy Rittich Avatar answered Dec 20 '25 07:12

D'Arcy Rittich



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!