tags:

views:

233

answers:

2

I have a django project, but for some reason basic jquery isn't working.

<html>
    <head>
        <link href="/site_media/css/poll.css" rel="stylesheet" type="text/css">
        <script type="text/javascript" src="/site_media/js/jquery-1.3.2.js" />
        <script type="text/javascript">
                $(document).ready(function(){
                    alert('hi there');
                });
        </script>
    </head>

etc...

For some reason the ready event isn't firing. The jquery and css are both definitely present (firebug confirms that for me). There are no javascript errors on the page.

Am I missing something totally obvious, or is there something subtle in Django that requires configuration to allow jQuery to work with it.

EDIT:In fact, no javascript works after importing jquery! Adding a

<script type="text/javascript">alert("hi");</script>

works if placed before the jquery import, but not after.

A: 

Do you have any other script blocks defined that are causing an error - this could cause the ready not to fire. Other things to try are to ensure the html vaidates at w3c, run the page in ie and see if that throws an error that firebug does not. Failing this then can you put the page live and I can investigate myself?

If the html renders as you have pasted then django can have no impact on the ready event not firing.

redsquare
+3  A: 

It could be due to the missing </script> end tag for the jQuery script inclusion line. For example:

<script type="text/javascript" src="/site_media/js/jquery-1.3.2.js"></script>

According to the note in the HTML specification for the SCRIPT element here, both the start and end tags are required.

ayaz
That was it! Thanks
Daniel