I have a document that may give the user the ability to run the same function more than once. Is there a way to check if the function is currently running before I can reactivate it again?
Use the typeof operator to check if a function is defined, e.g. typeof myFunction === 'function' . The typeof operator returns a string that indicates the type of a value.
ready(function() { }); So a jQuery function, which is prefixed with the $ or the word jQuery generally is called from within that method. $(document). ready(function() { // Assign all list items on the page to be the color red.
You can test if jQuery is loaded by opening your javascript console (in Chrome: Settings > More tools > Javascript console). Where the little blue arrow appears type: if(jQuery) alert('jQuery is loaded'); Press enter.
“This” keyword refers to an object that is executing the current piece of code. It references the object that is executing the current function. If the function being referenced is a regular function, “this” references the global object.
Set an external flag.
var functionIsRunning = false;
function myFunction() {
if (!functionIsRunning) {
functionIsRunning = true;
//do stuff
functionIsRunning = false;
}
}
The same principle applies to jQuery functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With