\n\n$(document).ready(function() { \n $(\"h1\").click(function() { \n $(this).css (\"color\", \"#fff\");\n })\n});","answerCount":14,"upvoteCount":1,"suggestedAnswer":[{"@type":"Answer","text":"Hello, Hacker !\nBut, I see everything works right for you.\n\n\n\n

Blue bird.

","upvoteCount":3},{"@type":"Answer","text":"Hacker,\nCan you attach your code here?","upvoteCount":3},{"@type":"Answer","text":"Hacker,\nPlease attach your jQuery library to the \nGood luck!","upvoteCount":2},{"@type":"Answer","text":"do I need to write the ","upvoteCount":1},{"@type":"Answer","text":"https://code.sololearn.com/WYhd09J438xu/?ref=app","upvoteCount":1},{"@type":"Answer","text":"That's a breakdown of the code","upvoteCount":0},{"@type":"Answer","text":"Alexander, Thank you","upvoteCount":0},{"@type":"Answer","text":"😣😣..it's still giving me the undefined on my laptop","upvoteCount":0},{"@type":"Answer","text":"already kept the script above","upvoteCount":0},{"@type":"Answer","text":"I dont think the \"this\" works....","upvoteCount":0},{"@type":"Answer","text":"Oh... No it works.","upvoteCount":0},{"@type":"Answer","text":"it works \"this\" represents the \"h1\" element I selected","upvoteCount":0},{"@type":"Answer","text":"EDIT: nevermind, I am wrong.\n\n$(\"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.\n\nTo select the first h1, use $(\"h1\").eq(0) .","upvoteCount":0},{"@type":"Answer","text":"The code you linked from the SoloLearn Playground works fine, so the problem is likely with your browser.","upvoteCount":0}]} }
+ 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