views:

39

answers:

2

I want to call a function only if the document is still loading.. how can I?

A: 

You could run a function normally in JavaScript and overwrite it within jQuery.ready:

function foo() {
    // …
}
$(document).ready(function() {
    foo = function() {};
});
foo();

Now if foo calls itself recursively, it will stop when foo is redefined when the document is ready.

Gumbo
Why not use a simple variable instead of a recursive method?
Marnix van Valen
+2  A: 

You could check document.readyState or use a simple variable in the global scope:

var ready = false;
$(document).ready(function () {
    ready = true;
});
Andy E