What happened to my simple jQuery hello world page?

I have a very simple jquery test page, and I can't 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 the warning window to appear when the page is ready.

There are no errors on the page, but the warning window does not appear. I think this is a very, very simple page, so I'm not sure what I am missing. Does anyone have any ideas?

+5
source share
3 answers

A couple of possible problems: missing DOCTYPEand incorrect quotation marks around the typetag attribute script.

Try the following:

<!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>
+7
source

Your worng tags <script type="text/javascript">should be

<script type="text/javascript">

<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>
+1
source

 <script type="text/javascript">

to

 <script type="text/javascript">

"  ---->>> "
+1

All Articles