Having trouble with jQuery | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Having trouble with jQuery

keeps telling me $ and ready are undefined and yes I kept the <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> $(document).ready(function() { $("h1").click(function() { $(this).css ("color", "#fff"); }) });

12th Jul 2018, 6:41 PM
Hacker
Hacker - avatar
14 Answers
+ 3
Hello, Hacker ! But, I see everything works right for you. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function() { $("h1").click(function() { $(this).css("color", "red"); }); }); </script> <h1>Blue bird.</h1>
12th Jul 2018, 7:03 PM
Alexander Sokolov
Alexander Sokolov - avatar
+ 3
Hacker, Can you attach your code here?
12th Jul 2018, 7:07 PM
Alexander Sokolov
Alexander Sokolov - avatar
+ 2
Hacker, Please attach your jQuery library to the <head> Good luck!
12th Jul 2018, 7:20 PM
Alexander Sokolov
Alexander Sokolov - avatar
+ 1
do I need to write the <script> tag in my .js file as you did <script> $(document).ready(function() { $("h1").click(function() { $(this).css("color", "red"); }); }); </script>
12th Jul 2018, 7:06 PM
Hacker
Hacker - avatar
0
That's a breakdown of the code
12th Jul 2018, 7:13 PM
Hacker
Hacker - avatar
0
Alexander, Thank you
12th Jul 2018, 7:48 PM
Hacker
Hacker - avatar
0
😣😣..it's still giving me the undefined on my laptop
12th Jul 2018, 8:06 PM
Hacker
Hacker - avatar
0
already kept the script above
12th Jul 2018, 8:07 PM
Hacker
Hacker - avatar
0
I dont think the "this" works....
13th Jul 2018, 2:07 AM
Paul Grasser
Paul Grasser - avatar
0
Oh... No it works.
13th Jul 2018, 2:08 AM
Paul Grasser
Paul Grasser - avatar
0
it works "this" represents the "h1" element I selected
13th Jul 2018, 7:21 AM
Hacker
Hacker - avatar
0
EDIT: nevermind, I am wrong. $("h1") selects all h1 elements and puts them into an object. Even if you only have one h1, it still puts it in an object. To select the first h1, use $("h1").eq(0) .
13th Jul 2018, 10:01 AM
James
James - avatar
0
The code you linked from the SoloLearn Playground works fine, so the problem is likely with your browser.
13th Jul 2018, 10:04 AM
James
James - avatar