How to check if jQuery library is loaded?
To check if jQuery library is loaded, use the following JavaScript code :
if (typeof jQuery != 'undefined') { alert("jQuery library is loaded!"); }else{ alert("jQuery library is not found!"); }
Alternative?
In some blogs and forum mention about the following alternative code :
if (jQuery) { alert("jQuery library is loaded!"); } else { alert("jQuery library is not found!"); }
However, this is not working, when the jQuery library is not loaded, this code will failed (jQuery is not define), and the alert message will never execute.
At last, the first jQuery checking method is always recommended.