views:

439

answers:

6

I have a method written in JavaScript let's say 'callme' and I have some jQuery code written within the block $(document.ready).

My question is how to call the existing JavaScript method 'callme' from within the jQuery block.

The assumed listing is as follows,

function callme(){
    // do some complex processing. I don't want to do this in jQuery
}

$(document).ready(function(){
    // I need to call callme function from here.
});

Please help me out.

+7  A: 

$(document).ready(function(){ callme()});

Dave
+4  A: 
$(document).ready(callme);
Lloyd
+4  A: 

It might be worth mentioning that there is also a shortcut available; simply $(callme);.

Cide
I don't think the OP knows where to put such a call.
Matt Ball
+2  A: 

Might be easier to read (it is for me, when things get more complicated), but exactly the same answer as Dave's:

$(document).ready( function()
{
     ...
     callme();
     ...
});
Matt Ball
+2  A: 

Nothing special you need to do. The $(document).ready() call is just a function, so you can feel free to call your other functions in there.

Remember, jQuery is still javascript. Everything just runs through the jQuery function to handle all the custom methods and such. Anything you can do in javascript, you can do in jQuery.

idrumgood
A: 

Why not just do the following?

$(function(){
   // Do your processing here
});

You don't really need to create a specific named function, unless of course you are going to execute it more than once after the page loads.

Also, what do you mean by "complex processing"? JavaScript isn't multi-threaded, so on one function can execute at a time. If your "complex processing" takes a long time, then the page will become unresponsive until it finishes.

Chris Pietschmann