Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with my simple jquery "hello world" page?

Tags:

jquery

I have a very simple jquery test page and I can't seem to get even the basics to work.

<html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script type=”text/javascript”>
            $(function(){
                alert('hi');
            }); 
        </script>
    </head>
    <body>
        This is a test
    </body>
</html>

Basically, I just want an alert box to pop up when the page is ready.

There are no errors on the page but the alert box doesn't show up. This seems to be a very, very simple page to me so I'm not sure what I'm missing. Does anyone have any ideas?

like image 951
stuck Avatar asked Sep 12 '11 09:09

stuck


1 Answers

Couple of possible problems: missing DOCTYPE and wrong quotes around type attribute of the script tag.

Try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script type="text/javascript">
            $(function(){
                alert('hi');
            }); 
        </script>
    </head>
    <body>
        This is a test
    </body>
</html>
like image 112
Shadow Wizard Hates Omicron Avatar answered Nov 05 '22 04:11

Shadow Wizard Hates Omicron