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
Stephen DelBuono
11,264 PointsIncluding jquery in our project challenge task 2
help here is my code
script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$( "#message" ).hide();
$( "#message" ).click(function() {
$( "#message" ).show( "slow" );
});></script>
Help how to fit this is appreciated. link to challenge: http://teamtreehouse.com/library/build-an-interactive-website/introduction-to-jquery/including-jquery-in-our-project
8 Answers
Stephen DelBuono
11,264 PointsThanks Adam, however I just didnt have the closed tag indented in my question but I fixed that but it still wont work. can you try my code in the challenge? not sure why it still wont work. thanks for your help.
Adam Sackfield
Courses Plus Student 19,663 PointsI got it pass by doing the following.
$(document).ready(function(){
$("#message").hide();
$("#message").show('slow');
});
Not sure if the document .ready function is required but its force of habit.
James Barnett
39,199 Points> Not sure if the document .ready function is required but its force of habit.
It's not.
Adam Sackfield
Courses Plus Student 19,663 PointsBetter to form good habits I would say! Cheers
James Barnett
39,199 PointsI would argue, that an exercise should be solved with as little code as possible. Including a line of code you aren't exactly sure how it contributes to the solution, but include it out of habit is symptom of cargo cult programming.
Adam Sackfield
Courses Plus Student 19,663 PointsWell not really as I was unsure if the code editor on here needed it. As if it was my project then I would want it wait for the page to load before running any kind of scripts. So as to enhance the site performance during a users visit. Happen I can guide you to research what being pedantic means.
Stephen DelBuono
11,264 PointsYes, I. did not have
(document). ready (function() {
so I'm guessing I need that to select the element in the DOM. Thanks for your help!!!
James Barnett
39,199 Points> so I'm guessing I need that to select the element in the DOM.
Nope.
James Barnett
39,199 Points $( "#message" ).hide();
$( "#message" ).click(function() {
$( "#message" ).show( "slow" );
});
In your code you say:
- Hide the element
- Listen for a a click on the (now hidden) element
- When a click is detected, show it slowly.
The obvious question, how does a user click on a hidden element.
Stephen DelBuono
11,264 Points.this is my code and its not passing
$( "#message" ).hide();
$( "#message" ).click(function() {
$( "#message" ).show( "slow" );
});
James Barnett
39,199 PointsThe code challenge has 2 parts, hide the element and then show the element. Your element will never be shown because a user can't click on a hidden element.
Let me know if you still have any questions.
Stephen DelBuono
11,264 Pointsthanks but I'm confused...I thought I was following the steps but I guess I am getting lost. so do i need a command to show it first? at this point its hidden but the user needs to be able to access it?
James Barnett
39,199 PointsThe directions don't mention anything about "clicking", I think that's the part that's tripping you up. If you cut that part out it should work fine.
Stephen DelBuono
11,264 PointsOk I took the click out. It still doesn't work. I've been stuck all afternoon, can someone help with this challenge?
$("#message").hide();
$("#message") (function() {
$("#message").show("slow")
});
Eric Jones
24,588 PointsI was stuck on this as well. Here is my code. It passed.
<script type="text/javascript"> $("#message").hide(); $("#message").show("slow"); </script>
Adam Sackfield
Courses Plus Student 19,663 PointsAdam Sackfield
Courses Plus Student 19,663 PointsYou havent closed your 2nd opening script tag
<script type="text/javascript"shoud be
<script type="text/javascript">Hope this helps