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
Luke Ayres
6,170 PointsIs there an obvious reason why JQuery isn't working for me?
SO I have the following two lines of code right before ```html </body>
```js
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="photo.js" type="text/javascript" charset="utf-8"></script>
What else do I need to do to get JQs CDN working? Google isn't recognizing the links?
4 Answers
Richard Duncan
5,568 PointsYou can include the jQuery library anywhere you like just make sure that your custom js file is after it in the document.
There is nothing wrong with your link to the jQuery library CDN as evidenced here: http://jsbin.com/vehimahu/1/ & here: http://jsbin.com/vehimahu/1/edit?html,js,console but you have missed type="text/javascript" from the script tag here.
There may be some issue linking to photo.js You can always try code out online at //jsbin.com //jsfiddle.net and //codepen.io if you just want to dive right into writing code.
Dave McFarland
Treehouse TeacherWhen you leave out the http in the src attribute like this <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>, the file WILL NOT load unless you view the page through a web server. If you put this in a web page you have on your computer, then choose File -> Open in Chrome to open the file, the jQuery file will not load.
Leaving off the http is called a "protocol-less" or "protocol-relative" URL. It's useful if you don't know whether you will be delivering your files via SSL (meaning a secure URL beginning with https://) or just through regular http. Without the http (or https) at the beginning you can send the file out using either SSL or without and not encounter any security warnings. You can read more about it at http://www.paulirish.com/2010/the-protocol-relative-url/
If you're sure you won't be hosting your pages using SSL, you're safe using the http protocol as Jeremy Germenis mentioned:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
Jonathan Grieve
Treehouse Moderator 91,254 PointsIt's one of my biggest headaches with linking jquery. I find myself spending more time making sure it works before I really get going coding.
Usually putting the link tag for jquery inside the header HTML element or just before the closing body tag works for me. But order is crucial just like it is for CSS rendering! :-)
Jeremy Germenis
29,854 Pointsuse this line instead:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
James Barnett
39,199 PointsJames Barnett
39,199 PointsRichard Duncan -
Seems like your link is broken.
Also ...
>you have missed type="text/javascript" from the script tag here.You no longer need that in HTML5.
source: http://stackoverflow.com/a/14323399/1756132
Richard Duncan
5,568 PointsRichard Duncan
5,568 PointsNope the link works just fine James Barnett but i've added a more direct one. If you click the edit button for jsbin in the top right hand corner on the original and look at the console, or inspect the console in your browser you will see what's going on there. Thought you'd know that as you seem to know everything else... ;)
James Barnett
39,199 PointsJames Barnett
39,199 PointsRichard Duncan -
>Thought you'd know that as you seem to know everything elseAt the time I posted that when you clicked the
editbutton it brought me to a 404 page. It's working now, guess jsbin may have been having issues.James Barnett
39,199 PointsJames Barnett
39,199 PointsRichard Duncan - However did you take note about
type="text/javascript"and how that's not an issue with the code challenge as it's now valid in HTML5 to omit that.Richard Duncan
5,568 PointsRichard Duncan
5,568 PointsI did read the W3C recommendation and I saw that it is optional yes I also noted the date of the draft was yesterday the 15th of April, I'm wondering if the code challenge can pick this weekends lottery numbers for me? very interesting though and good to know it defaults to text/javascript if no type is set.
I thought it worth pointing out that on the photo.js include he had that optional type but on the jQuery CDN he did not. I didn't say remove it just that it was missed.
James Barnett
39,199 PointsJames Barnett
39,199 PointsRichard Duncan -
>I also noted the date of the draft was yesterday the 15th of April, I'm wondering if the code challenge can pick this weekends lottery numbers for me.What you looked was the Nightly version of the spec it contains all of the current updates as of the day before.
The
typeattribute was declared optional in the 2nd version of the HTML5 spec which came out back in June of '08.Sorry for the confusion.