+ 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"); }) });
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>
+ 3
Hacker,
Can you attach your code here?
+ 2
Hacker,
Please attach your jQuery library to the <head>
Good luck!
+ 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>
0
That's a breakdown of the code
0
Alexander, Thank you
0
đŁđŁ..it's still giving me the undefined on my laptop
0
already kept the script above
0
I dont think the "this" works....
0
Oh... No it works.
0
it works "this" represents the "h1" element I selected
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) .
0
The code you linked from the SoloLearn Playground works fine, so the problem is likely with your browser.