views:

213

answers:

4

I'm trying JQUERY on my machine, but for some reason, nothing seems to work. Here's the test file:

<html>
<head>
<script type="text/css" src="jquery.js">
</script>
<script type="text/javascript">
    $("p").mouseover(function () {
      $(this).css("color","black");
    });

    $(document).ready(function(){
$("body").css("background-color","black");
$("body").css("color","white");
});
</script>
</head>
<body>
<h1>This is a test</h1>
<p>Roll over me!</p>
</body>
</html>

Nothing in there works. Also, if anybody wants to know, accessing through my domain and through the local both don't work. I'm really confused, because I copied most of that code off the internet, just in case there was something wrong with my typing.

For some reason, firefox is throwing this error:

Code: Evaluate
$ is not defined
http://hussain.mooo.com/jq.html
Line: 6
$ is not defined
http://hussain.mooo.com/jq.html
Line: 6

New code (moved the p onmouseover handeler)

    <script src="jquery.js" type="text/css">
</script>
<script type="text/javascript">
$(document).ready(function(){
    $("p").mouseover(function () {
      $(this).css("color","black");
    });
$("body").css("background-color","black");
$("body").css("color","white");
});
</script>
+20  A: 

Specify correct type for javascript file:

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

Update

You're currently using type="text/css" as content type for javascript file which is incorrect. Try to copy above code into your script.

Screenshot

alt text

Ivan Nevostruev
the best solutions are oftentimes the most obvious ones... haha
Jason
Or just remove it. The "type" attribute is unnecessary (and potentially dangerous, it seems) for script tags.
Corey Porter
You got **way** too much upvotes, regardless a +1 for the screenshot :)
BalusC
+1 for screenshot also.
Stefan Kendall
Way too many (+1 anyway).
Upper Stage
A: 

Install firebug and see what it tells you in the Console tab.

Ned Batchelder
A: 

You should move the attachment of the mouseover handler into $(document).ready(...) because the paragraph won't necessarily exist until the document is ready and so no handler can be attached to it.

Rich
A: 

Download the latest version of jQuery "jquery-1.3.2.min.js" and link the file correctly. and try this,

<script type="text/javascript">
$(function(){
    $("p").mouseover(function () {
      $(this).css("color","black");
    });

    $("body").css("background-color","black");
    $("body").css("color","white");
});
</script>
mukamaivan
I have the latest version installed (I just redownloaded it), still nothing.
Hussain
Install firefox firebug and enable the console and refresh the page, see what it tells you: 1. if you cant see the jquery.js then you need to link it properly, if you cant see anything then your java script is disabled... try checking that.
mukamaivan