I want to call a function only if the document is still loading.. how can I?
views:
39answers:
2
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
2010-06-12 14:34:16
Why not use a simple variable instead of a recursive method?
Marnix van Valen
2010-06-12 14:41:19
+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
2010-06-12 14:34:34