Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rerun $(document).ready()

I have a number different functions on different pages that are bound $(document).ready(). I am writing an Ajax login script and want to be able to refresh the page state to reflect the changed login status without reloading the whole page. I'm hoping there's a nice simple way of doing this so I don't restructure all my other scripts.

Any ideas?

like image 789
HuwD Avatar asked Nov 21 '25 13:11

HuwD


1 Answers

You can do something like this:

$(document).on('ready readyAgain', function() {
    // do stuff
});

// At some other point in time, just trigger readyAgain
$(document).trigger('readyAgain');

Note:

$(document).on('ready') has been deprecated in jQuery 1.8 according to documentation. An alternative method is as follows:

function myReadyFunction(){}
$(myReadyFunction);

// at some other point, just call your function whenever needed:
myReadyFunction($);
like image 180
void Avatar answered Nov 24 '25 02:11

void



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!