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

Getting held up trying to learn jQuery

I'm doing examples from the Headstart books (keep opinions to yourself please), and for reasons I cannot figure out, the examples are unresponsive on clicks, etc.

I get the feeling my script tags are in the wrong place? Or maybe I'm not using the proper version of jQuery? So confused. Codepen below.

http://cdpn.io/xlmnI

Thanks.

4 Answers

Tom:

   $(document).ready(function(){ 
  $("#clickMe").click(function() {
    $('img').fadeIn(1000);
    $('#picframe').slideToggle("slow");
  });
});

no closing tag on 'img' , and the curly braces go inside of the parentheses.

Thanks, but that button is still unresponsive....

Figured it out. Didn't have a downloaded version of jQuery in a folder that held the CSS and HTML. Right?

On Codepen, you can just toggle the latest version of jQuery (or other JavaScript libraries) on and off under the JS section. That's what I did.

While we're at it...why won't this work?

http://codepen.io/anon/pen/pLGcB

I'm not understanding why nothing's happening. This code is straight copy and pasted from the book, so there shouldn't be any errors.

If you move the CSS and JS into the appropriate sections on Codepen, it works just fine. Be sure to delete the comments in the Javascript if you move it over.

Moved everything over and deleted comments...still unresponsive for me.

http://cdpn.io/pLGcB (with changes).

If you click on the button in the bottom left, Edit This Pen, it works over there. Have you tried this in a regular browser?

Looking at this in Chrome, I found it unresponsive in both full and edit views.

Using <script src="scripts/jquery-1.6.2.min.js"></script> to pull down jquery won't work on codepen because you are not physically storing the jquery library at that location on the site.

2 options:

1) Use a CDN to pull down jquery, like <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

2) use the jquery library available if you click the cog beside JS over the javascript editor in codepen.

of course, the CDN was escaped, lets try this again:

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

I can't remember if I mentioned it to Tom previously, that gear icon in the top right of the JS let's you load JavaScript libraries, including the latest version of jQuery. Using the sections on code pen for HTML, CSS, and JavaScript, I was able to make his pen work, but I had to separate out the pieces.