Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
138
rated 0 times [  145] [ 7]  / answers: 1 / hits: 26059  / 12 Years ago, thu, june 7, 2012, 12:00:00

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);

});


});

More From » jquery

 Answers
20

Problem 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 */ });

[#85088] Wednesday, June 6, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaycie

Total Points: 414
Total Questions: 96
Total Answers: 117

Location: Christmas Island
Member since Mon, Oct 19, 2020
4 Years ago
;