+ 2

Why is it that placing jQuery code inside the body or head does not work normally?

<script src="https://code.jquery.com/jquery-3.1.1.js"> </script> //inside head $(function() { $("a").attr("style", "color:green;"); }); //on JS page works, but.... <script src="https://code.jquery.com/jquery-3.1.1.js"> $(function() { $("p").attr("style", "color:green;"); }); </script>. // together inside head or in body does not work.... However, this will work without jQuery, using only JS normally.

15th Sep 2020, 5:31 PM
Jackie Tate
Jackie Tate - avatar
4 Respostas
+ 1
yeah, I tried that, too. <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'>$(function() { $("a").attr("style", "color:green;"); }); </script> inside the head element does not work, either. Even though the Ajax does work if I place the jQuery inside of Sololearns JS tab.
15th Sep 2020, 8:51 PM
Jackie Tate
Jackie Tate - avatar
+ 1
Martin Taylor that's what the issue was thx. I didn't realize that you had to use two separate script tags.
18th Sep 2020, 5:10 AM
Jackie Tate
Jackie Tate - avatar
0
Just insert <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script> in the head tag
15th Sep 2020, 6:18 PM
Dcc Lord
Dcc Lord - avatar