-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.

7
  • 3
    Make sure you have entered correct path location. Commented May 2, 2015 at 5:24
  • am a beginner,,could you please specify how to fix this Commented May 2, 2015 at 5:25
  • @ShaunakD it is working this way as well jsfiddle.net/qmsq3Lqr Commented May 2, 2015 at 5:27
  • If you go to view page source and then click on jquery.js. If it is showing that file not found then file is not included. Commented May 2, 2015 at 5:27
  • @ShaunakD it still works, what does that mean btw? Commented May 2, 2015 at 5:32

3 Answers 3

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>
Sign up to request clarification or add additional context in comments.

2 Comments

using <script src="code.jquery.com/jquery-2.1.4.min.js"></script> works great..but i can open js file by view source option....what was problem in my previous code
@Anonymous if you include the code I wrote above, but continue to use your <script src="js/..., does it work?
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.

Comments

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 ....................

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.