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

Code Challege: Introduction to jQuery

Question: 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".

My code:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $(".message").hide().before("<a href='#' class='message'>Order Now</a>");
            $(".message").click(function(){
                var $link = $(this);
                $link.next().show("slow").prev().remove();
                return false;
            });
  </script>

What am I doing wrong?

Thank you.

12 Answers

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Barry-Alan MacRae

I believe you're on this task 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".

It looks like your code works but it could be to do where you're placing it. It should look like this:

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

Regard Andrew

@Andrew

Thanks for your help, it worked!

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

I'm using the $("#message").hide().show("slow"); and it keeps giving me an error message "Call the hide() method and then show(), pass in the string "slow""

But for me this is not working.....

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

Hey Kevin,

Thanks for being a Treehouse Student! We'll get you an answer on this as soon as we can :)

Best, Ryan

Founder/CEO, Treehouse

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Kevin,

It seems you've got a lot of code in the second script tag that isn't required.

I'd remove everything and start from scratch:

The question is asking you to:

1) select a div with the id of "message", "#message" not the class of "message", ".message". If you're unfamiliar with CSS check out the CSS deep dive.

2) Hide that with the .hide() method

3) Then show it with the .show() method passing in the string parameter of "slow".

Let me know how you get on!

Regards, Andrew

I ran into the same problem, until I noticed that the instruction actually said to "show". Duh.

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Can you share your code in context with the rest of your code?

you have to make sure your </script> is after your code

Can anyone find my mistake, error messages says "Call the hide() method and then show(), pass in the string "slow"

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

Can I just ask that the following code I wrote is correct but obviously a bit more effort than the solution?

$("#message").hide(function(){ $("#message").show("fast"); });

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

I believe [hide()](api.jquery.com/hide/) can either take no arguments, 1 the speed or 2 the speed and completion callback so $("#message").hide(0, function(){ $("#message").show("fast"); }); should hide it 0 milliseconds and show it on the completion of the hide.

Thanks Andrew!