Javascript – Calling jQuery’s DOM ready function from another function


Is it possible to call jQuery's $(document).ready function from within another Javascript function? I have a button, which when clicked should call the jQuery DOM ready function. Is this possible?

Best Solution

If you are calling it from another javascript function, drop the $(document).ready part

function f1(){

or if you want to call a function only when the document is ready, put the function call inside $(document).ready

 function f1(){
  //do something here

But you are not taking advantage of jquery's full functionality here. If you want to associate an onclick event with an element, you can do it like so:

<button id='button1'></button>

In the js file:

 //do the onclick sequence here