Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Introduction to jQuery Ways to Include jQuery in a Project

code not working

I could not find the text to copy and paste on jquery website so I copied from video and pasted in here:

    <title>Take Evasive Action</title>
    <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">


  <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

  <script src="js/app.js" type="text/javascript" charset="utf-8"></script>
</head>```

but for some reason the following code does not work and I am guessing it is caused by
the *<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>* 

```function myCode() {
    $(".warning").hide().show("slow");
}




$(document).ready(myCode);```

5 Answers

Ari Misha
Ari Misha
19,323 Points

Hiya James! There is a website i always go to when i need inline link for libraries to add to my HTML. you can visit the website here. Visit this site and type "jquery" in search box and the link will appear on the right. Copy the link and paste in your HTML. (:

~ Ari

Ari Misha
Ari Misha
19,323 Points

btw you dont need to define a separate function to call, you can the whole function as the callback function to .ready() method. This is how its done:

$(document).ready(function() {
  $(".warning").hide().show("slow");
});

See how elegant it looks. (P.S.: Just an advice , but your way is the correct way as well)(:

Hiya Ari! For my education and perhaps others, could you please tell me what this code *the link : <script src= https://cdnjs.cloudfl..........*is doing, I think it is loading a library (a collection of code?) which is some sort of reference needed for jquery to function by way of reference; but then why did the other reference not work? Could you explain please?

Ari Misha
Ari Misha
19,323 Points

jQuery is a library extended on JavaScript, okay? Its not a framework or a language itself, its just a library that extends the JavaScript. In order to browser to understand the jQuery library, we have a couple of ways to point our browser to the jQuery library itself. First one is the easiest way in my opinion, download the library itself and mention the path to the library in script tags in the head tags of your HTML. With jQuery running on your local machine, you could do development offline as well. But with the second option , i.e. point the direction to the library's link , i mean the url, needs an internet connection. When your browser loads the DOM, browser looks for scripts included in your HTML in order to read 'em and load on the front end. So it goes to the link we mentioned in the script tags , fetch all the data behind the scenes and now browser has the ability to understand the code. I think its pretty cool, right? (:

Many thanks Ari, that solved it I followed your instructions and then copy pasted * <script src= https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js></script>* into index.html file and then code worked.

Ari Misha
Ari Misha
19,323 Points

No worries! Bookmark this website, its hella useful. Plus they have the links to official GitHub page of the whole project so yeah no room for errors left. (:

hey I just saw this page it is infoprmative about the src attribute:http://www.jibbering.com/faq/faq_notes/script_tags.html

Hi Ari, okay I saw your reply now many thanks.

good to know how to work with jquery offline, thanks Ari.