For some reason the external .js file I am linking to isn't working. I am linking to it like so:
<script src="jquery.js" type="text/javascript"></script>
<script src=".7.2/jquery.min.js" type="text/javascript"></script>
I have tested jquery using a simple inline script to hide a paragraph of text when it is clicked on so the jquery library is present and working.
The jquery.js file is in the same folder as the index.php file that is calling it.
What am I doing wrong?
This is the code I have in the external .js file currently just to test it is working(it isn't):
$("document").ready(function(){
$("p").click(function(){
$("p").css("color", "red");
});
});
For some reason the external .js file I am linking to isn't working. I am linking to it like so:
<script src="jquery.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
I have tested jquery using a simple inline script to hide a paragraph of text when it is clicked on so the jquery library is present and working.
The jquery.js file is in the same folder as the index.php file that is calling it.
What am I doing wrong?
This is the code I have in the external .js file currently just to test it is working(it isn't):
$("document").ready(function(){
$("p").click(function(){
$("p").css("color", "red");
});
});
Share
Improve this question
asked Jun 7, 2012 at 14:51
crmephamcrmepham
4,74019 gold badges86 silver badges162 bronze badges
3
- why are you including 2 versions of jQuery? – dnagirl Commented Jun 7, 2012 at 14:54
- the jquery.js file is not the jquery library, just what I have called the .js file. – crmepham Commented Jun 7, 2012 at 14:55
- 2 Shouldn't it be $(document) instead of $("document")? – bm1729 Commented Jun 7, 2012 at 14:56
1 Answer
Reset to default 21Problem 1
It looks like jquery.js contains the code you wrote that depends on jQuery.
You need to load jQuery before you try to use it.
Swap the order of the <script>
elements.
Problem 2
$("document")
will wait for <document>
elements to be ready. HTML doesn't have such a thing. Lose the quotes to pass in the document
object directly.
Better yet, forget about the explicit call to ready
and just
jQuery(function () { /* your function */ });