0

the error that occurred usually happen if I don't include:

<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>

In the code or I put the jquery before I put script src. The problem is I did not do anything wrong with it yet still get the error.

Is there anything that I might be overlooked in order to fix the error?

4
  • You must include jQuery before any related code. Commented Apr 18, 2019 at 4:11
  • that's the problem I currently experienced. already include the jquery reference but the same error keep popup Commented Apr 18, 2019 at 4:19
  • 1.You have to put jquery base/core library before any other library/code-snippet. 2.sometime it happens when two different libraries got conflicted [one of them using older version like jQuery and some one want new version with $].3 sometime it happens when other libraries not putted in correct manner, means to say that may any library need to put first but you putted it after other-one Commented Apr 18, 2019 at 4:38
  • This question would be greatly improved by the inclusion of a minimal reproducible example. It would also benefit from the exact text of the error message that appears in the console including the location of where it is occurring. Commented Apr 18, 2019 at 5:13

2 Answers 2

1

You must include jquery before any script which uses jquery.

Why '$' is undefined?

Case: 1 Because jQuery is a javascript library(collection of class and methods). When it is used on a web page it creates its own object. $ holds the reference of that object. Later at any point of time we can use $ to use any jQuery method. e.g $.each(),$.get()...etc

So before use of jQuery method in your code or any other js library in code which uses jQuery must include after jQuery.

Case: 2 You should check into the browser's console (to reach, press F12 then go into console tab). There might be chance that your code before jQuery inclusion has some error.

Sign up to request clarification or add additional context in comments.

1 Comment

So what's your case in the above cases?
0

Every code which uses jquery, should be placed after jquery script tag. I don't know how your code lines are aligned, so I'll give you the example of the wrong cases.

Wrong cases:

#1

<head>
  <script> $... </script>
</head>
<body>
  <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
</body>

#2

<head>
  <script> $... </script>
  <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
</body>

#3

<head>
</head>
<body>
  <script> $... </script>
  <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
</body>

$... also indicates jquery dependent libraries such as jquery.ui.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.