1

I have searched a lot and unable to find a fix for my rather simple problem.

I am unable to embed jQuery in my javascript code. I have downloaded the latest version of jquery from http://jquery.com/download/ and have downloaded the compressed, production version 3.2.1. I, then, saved the file on my local(which is in the same folder as the HTML file) and referenced it in my code like below :

<!DOCTYPE html>
<html>
<head>
   <title>Learning jQuery</title>
   <script type="text/javascript"  src="jquery.min.js"></script>
</head>
<body>
   <script>
      if(typeof jQuery != "undefined" ){
         alert("jquery is installed");
      }else{
         alert("jquery not installed");
      }
   </script>
</body>
</html>

Every time I execute this on a browser, it always pops up "jQuery not installed", instead of "jquery is installed".

Can anyone please help and point out what wrong am I doing here. Thanks in advance.

Folder Structure

priyesh
  • 13
  • 4

2 Answers2

1

Works fine for me https://jsfiddle.net/ajLrj0Lg/

Your jquery.min.js file:

  • has different name.
  • it's in wrong folder.
  • is corrupted

Just check web console (Press F12 in Chrome or Firefox) for errors.

Please mind on linux check files are case sensititive.

Peter
  • 16,453
  • 8
  • 51
  • 77
  • Hey thanks. Your code worked. Just wondering what was wrong with my code. No, there are no errors on the console as well. – priyesh Apr 27 '17 at 10:33
  • @user3069742 `Just wondering what was wrong with my code` can you show me screenshot of your folder and contents of `jquery.min.js`? – Peter Apr 27 '17 at 10:34
  • I have added the image of folder structure. The contents of min.js file is js code. Not able to add 2nd screenshot as I don't have enough points. :-( – priyesh Apr 27 '17 at 11:00
  • @priyesh run this http://qwe.ninja/misc/jq.zip either `jquery.min.js` is corrupted or you use different code – Peter Apr 27 '17 at 13:41
0

Try to put your JS code in an onload functions.

window.onload = function() {
     if(typeof jQuery != "undefined" ){
         alert("jquery is installed");
     }
     else{
         alert("jquery not installed");
     }
 }

This will make sure all DOM Elements loaded.

NullDev
  • 6,739
  • 4
  • 30
  • 54