lethalMango
lethalMango

Reputation: 4491

jQuery alert box doesn't appear

I have been stumped on this for about an hour. I have the following code that doesn't load the alert box when the page loads.

I have tried on two different machines with no avail (JS is enabled on both machines using both Chrome and FF).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title><?php echo $pageTitle; ?></title>

  <link href="../css/style.css" rel="stylesheet" type="text/css" media="all" />
  <link href="/favicon.ico" rel="shortcut icon" type="image/x-icon" />
  <!--[if !IE 7]>
    <style type="text/css">
        #wrap {display:table;height:100%}
    </style>
  <![endif]-->

  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
  <script type="text/javascript">
  $(document).ready(function() {
      alert("hello");
  }
  </script>
</head>

<body>
  ...
</body>
</html>

Upvotes: 0

Views: 2566

Answers (5)

Eric Fortis
Eric Fortis

Reputation: 17360

$(document).ready(function() {
    alert("hello");
});                     //note this line

Upvotes: 8

andyb
andyb

Reputation: 43823

You cannot close the <script> tag in the shorthand way you need to use <script></script>. Also the jQuery wrapper needs to be wrapped with

$(document).ready(function() {
    ...
});

or just

$(function(){
    ...
});

Upvotes: 0

Daniel Iankov
Daniel Iankov

Reputation: 306

you miss closing ); before the tag

Upvotes: 2

lahsrah
lahsrah

Reputation: 9183

Replace your script with this:

  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
  <script type="text/javascript">
      $(document).ready(function() {
          alert("hello");
      });
  </script>

For some reason you can't close the script tag with just a /> to close. You need a closing element. Also you are missing the closing bracket on your jquery ready function.

Upvotes: 3

p.campbell
p.campbell

Reputation: 100637

You're missing your closing parenthesis and semi-colon:

  <script type="text/javascript">
  $(document).ready(function() {
      alert("hello");
  });
  </script>

Upvotes: 3

Related Questions