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 What is jQuery?

Akhter Rasool
Akhter Rasool
8,597 Points

Including jquery

is it necessary to include jquery in each and every html file? If yes, how do i do that? and what's the name of the file ?

Kody Bentley
Kody Bentley
4,411 Points

Hello,

Yes as far as I know you must include Jquery in every html file that is loaded. The most simple way to do this is using CDN which stands for Content Delivery Network. As shown in this example at the end of the body tag the Jquery CDN script tag found at http://jquery.com/download/ the specific tag you are looking for is the second line from the bottom of the code, and the first script tag.

<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>

<!DOCTYPE html> <html> <head> <title>Star Wars Spoilers</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8"> </head> <body> <img src="img/deathstar.png" /> <p class="spoiler"> <!--Spoiler:--> <span class="spoiler2">Darth Vader is Luke Skywalker's Father! Noooooooooooo!</span>

</p>
<script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/app.js" type="text/javascript" charset="utf-8"></script>

</body> </html>

I hope this was helpful for you.

2 Answers

works in chrome for me

Charissa Schouten
Charissa Schouten
1,976 Points

The files can be loaded in through a <script> tag as Kody said. A lot of modern sites use so called partial views, in that case the JQuery only needs to be loaded in the layout view in which they live, sort a speak. You can always choose to load from an external url or provide a local version (or both where the local version is more of a back-up).