1

I'm trying to do a tutorial. I did one tutorial and things were great. Moving onto another and I can't get it to work. I'm only posting because I just started this tutorial and things aren't working. When 'Hello World' doesn't work I get frustrated. Anyway, here is my HTML. Nothing special here. I'm expecting a Hello World alert on page load, but I get nothing.

<html>                                                                  
<head>                                                                  
    <script type="text/javascript" src="jquery.js"></script>          
    <script type="text/javascript">  

        $(document).ready(function() {
    alert("Hello World");
    });

    </script>  

</head>                                                                 
<body>                                                                  
    <h2>My jQuery Test page</h2>
    <a href="http://www.google.com">Google</a>
<br>                                      
    <a href="http://www.yahoo.com">Yahoo</a>
</body>                                                                 

The original code was more complex, but it won't work either.

$(document).ready(function() {
   $("a").click(function() {
     alert("Hello world!");
   });
 });
3
  • check the path of your jquery file you specified in the src attribute. Commented Apr 8, 2011 at 14:27
  • As people said below - your jquery.js isn't in the same directory. The code is valid. Commented Apr 8, 2011 at 14:27
  • I'm guessing jQuery just isn't being loaded. If this is the case, you should see something like ReferenceError: $ is not defined in your console. Commented Apr 8, 2011 at 14:28

3 Answers 3

6

The issue might be the reference for the jquery.js, as the code that you have appears correct. (You can find more information regarding both directly including jQuery or using a CDN here.)

You may want to check that your code is in the proper directory, or if you are having difficulty you can use one of the CDN hosted versions by including:

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js”>
</script>

Demo

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

2 Comments

The file existed but the file was empty. After using Rionmonster's link and getting it to work, I found the issue.
Glad you were able to find a solution :)
1

Only thing i could think of is that the jquery.js doesn't exist.

Comments

1

Sounds like your are getting a javascript error. Possibly your jquery path is incorrect. You could try including your jquery from google:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.js"></script>

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.