0

Is it possible to manually refire a function that has been assigned to document's onready event?

I know this is an awkward question, and it's kinda difficult to explain the situation here, but please suppose we have

$(document).ready(function() {
    console.log('Hello World!');
}

Is there a way to manually trigger this event somehow somewhere in the page? like following

<script type="text/javascript">
    $(document).trigger('ready');
</script>

But this doesn't work unfortunately. Any suggestions?

David Weng
  • 4,165
  • 12
  • 42
  • 51
  • are you able to alter the script file holding the $(document).ready() statement ? – Scott Evernden Sep 21 '11 at 06:06
  • also this appears to be a repeat of http://stackoverflow.com/questions/562229/how-to-trigger-ready-in-jquery – Scott Evernden Sep 21 '11 at 06:07
  • the jQuery `.ready()` function only allows itself to be called once. You will have to do something like Scott suggests (put your code into a function) if you want to call the code again. – jfriend00 Sep 21 '11 at 06:15

1 Answers1

5

why ? cant you simply

function readyFunc() {
    console.log('Hello World!');
}

$(document).ready(readyFunc);

then you can just call the function as needed directly

Scott Evernden
  • 39,136
  • 15
  • 78
  • 84
  • the hastiness with which you have punctuated this answer is only matched by its clarity through brevity. +1 good sir. – Michael Jasper Sep 21 '11 at 06:08
  • No, unfortunately I have no access to the actual source. I'm doing some XHR stuff and the loaded content needs to be initialized by that js function. I need to somehow fire that event to make this work. – David Weng Sep 21 '11 at 06:35