I have this code in a global JS file.
$(document).ready(function() {
DoStuff();
});
Unfortunately there are pages that include this file but doesn't include the jquery file. So I get errors:
Message: The value of the property '$' is null or undefined,
not a Function object
How do I run document.ready() only if JQuery file is loaded.
if(window.jQuery) {
$(document).ready(function() {
DoStuff();
});
}
UPDATE
Check for window.jQuery instead of just jQuery. This should circumvent the "not defined" error.
You would test for the existence of jQuery first:
if(jQuery)
{
$(document).ready(function() { ... });
}
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