jreddy
jreddy

Reputation: 141

Simple jQuery question

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!");
   });
 });

Upvotes: 1

Views: 111

Answers (3)

Rion Williams
Rion Williams

Reputation: 76557

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

Upvotes: 6

ChrisThompson
ChrisThompson

Reputation: 2008

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>

Upvotes: 1

Andy
Andy

Reputation: 30135

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

Upvotes: 1

Related Questions