-1
<html>
<head>
    <title>JQuery beginning</title>
</head>
<body>
    <script type="type/javascript" src="js/jquery.js"></script>
    <p onclick="$(this).hide();">Test</p>
</body>
</html>

This is my html file. I have placed the downloaded js file in js folder inside the folder which is containing the above HTML file.

I am getting Uncaught ReferenceError: $ is not defined, when I click on "Test," instead of its being hidden.

dda
  • 6,030
  • 2
  • 25
  • 34
Anonymous
  • 1
  • 1
  • 2

3 Answers3

3

This means jQuery.js cannot be found at js/jquery.js. The file must be nonexistent or in another directory. You should check whether it is indeed called jQuery.js instead of something like jquery-2.1.4.min.js. If you cannot move it to the correct place, consider using the jQuery CDN:

<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>

Also, the use of inline JavaScript is extremely discouraged. You should make another script tag like this:

<script type="text/javascript">
    $(document).ready(function () {
        $("p").click(function () {
            $(this).hide();
        })
    })
</script>
royhowie
  • 11,075
  • 14
  • 50
  • 67
2

You will need to include jquery.min.js to your directory and page to implement jquery functionality.

you can include it as follows:

<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>

else you can give local directory path for the same,This path should be specific, like this:

<script src="~/Scripts/jquery-1.8.2.min.js"></script>

and then implement your code in :

<script type="text/javascript">
    $(document).ready(function () {
         // Your code here
    });
</script>

This will solve your issue.

VikrantMore
  • 903
  • 7
  • 25
0
<html>
<head>
    <title>JQuery beginning</title>
</head>
<body>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>

    <p id="para" onClick="$(this).hide();">Test</p>
</body>
</html>

use this ....................
Madhu
  • 1
  • 1