priyesh
priyesh

Reputation: 13

Unable to embed jquery in my javascript code

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

Upvotes: 1

Views: 109

Answers (2)

Peter
Peter

Reputation: 16923

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.

Upvotes: 1

NullDev
NullDev

Reputation: 7303

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.

Upvotes: 0

Related Questions