Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Help needed for Introduction to jQuery>including jQuery in our project Task 2/5

I'm am absolutely terrible at jQuery, and I only understand half of this question.

The link to the challenge is here: http://teamtreehouse.com/library/websites/build-an-interactive-website/introduction-to-jquery/including-jquery-in-our-project-2

"In the second script tag, write the jQuery code to hide the div with the id "message" and then show it slowly by passing in the string "slow".

The code is:

<!DOCTYPE html> <html> <body>

<div id="message"> <p>Congratulations!</p> </div>

<ul> <li class="removable">Item 1</li> <li class="removable">Item 2</li> <li class="removable">Item 3</li> </ul>

<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"

</script> </body> </html>

I know I need to input $(".message").hide();

<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" $("#message").hide().slow();

</script>

but then I don't quite understand the meaning of making it passing slowly in the second string. I'm really terrible at jQuery, so some terminology really doesn't stick with me. I'm still not quite sure what a string is in jQuery.

Sorry for the noobishness, hoping to solve this soon.

3 Answers

Ian Lunn
Ian Lunn
4,558 Points

Use the following:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    $('#message').hide().show('slow');
  });
</script>

First you've hidden the message using .hide(), then you've chained the .show() function to make it show again. "Passing in the string" is putting "slow" inside of the function.

The challenge instructions ask to hide the div with the id "message" and then show it slowly by passing in the string "slow"

$("#message").hide().show("slow");

however your solution pass as well...

something that I never see consistency with is the '.' over '#' use. In the lesson it says that a class is searched using '#' and an id is searched using '.' but in this case only '#' works. why is that?

James Barnett
James Barnett
39,199 Points

I think you've gotten confused somewhere. Ids are always # and classes are always .

Do you have a link (and time index) to any videos on Treehouse that say otherwise they should be filed as QA bugs.

James Barnett
James Barnett
39,199 Points

I'd suggest you go through the JavaScript foundations course on Treehouse. They even have a whole badge just about strngs

Thank you both very much! I guess I got too narrow focused on learning how to make a website, I didn't bother looking into the main foundations further. I will definitely give it a go though, so once again thank you both very much!