Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if jquery is loaded using Javascript

I am attempting to check if my Jquery Library is loaded onto my HTML page. I am checking to see if it works, but something is not right. Here is what I have:

<html xmlns="http://www.w3.org/1999/xhtml">     <head>         <script type="text/javascript" src="/query-1.6.3.min.js"></script>         <script type="text/javascript">           $(document).ready(function(){              if (jQuery) {                  // jQuery is loaded                  alert("Yeah!");              } else {                // jQuery is not loaded                alert("Doesn't Work");              }           });         </script> 
like image 743
SoftwareSavant Avatar asked Sep 08 '11 00:09

SoftwareSavant


People also ask

How do I tell what version of jQuery is loaded?

Type this command in the Chrome Developer Tools Javascript console window to see what version of the jQuery is being used on this page: console. log(jQuery(). jquery);


1 Answers

something is not right

Well, you are using jQuery to check for the presence of jQuery. If jQuery isn't loaded then $() won't even run at all and your callback won't execute, unless you're using another library and that library happens to share the same $() syntax.

Remove your $(document).ready() (use something like window.onload instead):

window.onload = function() {     if (window.jQuery) {           // jQuery is loaded           alert("Yeah!");     } else {         // jQuery is not loaded         alert("Doesn't Work");     } } 
like image 199
BoltClock Avatar answered Sep 21 '22 06:09

BoltClock