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

problem with output

i have pasted the below in index.html

<!DOCTYPE html>
<html>
<head>
    <title>Take Evasive Action</title>
    <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
  <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
  <script src="js/app.js" type="text/javascript" charset="utf-8"></script>
</body>
</head>
<body>
  <p class="warning">
    <span>It's A Trap!</span>
  </p>
  <div class="image">
    <img src="img/ackbar.gif" />
  </div>    
</html>

and in

app.js

//Hide Warning
//Show Warning Slowly
$(".warning").hide().show("slow");

$(document).ready(myCode);

but unable to see the out put shown in the video and here is the video link

http://teamtreehouse.com/library/jquery-basics/introduction-to-jquery/-ways-to-include-jquery-in-a-project

1 Answer

Hi harsha,

The main reason why you're not getting the desired result is because your code is executing before the DOM is ready, what this means is your jQuery selector can't find the .warning element therefore the hide() and show() methods can't be executed as the resulting selector will return a object with a length of 0 and no matching elements.

As you have a document ready statement in your above code you should by the look of it be doing something such as the following.

$(document).ready(function() {
    $(".warning").hide().show("slow");
});

Over the years this has become somewhat of a bad practice so it's highly recommend you move all your JavaScript execute to just before your ending </body> tag is then you can execute code on the DOM without needing to execute the $(document).ready() method.