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 jQuery Basics (2014) Introduction to jQuery What is jQuery?

Mehdi Amir
Mehdi Amir
658 Points

the warning does not hide ... pls help

<!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"> </head> <body> <p class="warning"> <span>It's A Trap!</span> </p> <div class="image"> <img src="img/ackbar.gif" /> </div> <script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script> <script src="js/app.js" type="text/javascript" charset="utf-8"></script> </body> </html>


jQuery(".warning").hide();


Warning sign is still showing. What am I doing wrong?

4 Answers

You are trying to select elements with the warning class with jQuery(".warning") , but there are no elements in your code with the warning class. The code below shows the original .html workspace file with the "p" element that had the warning class.

<!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">
</head>
<body>
  <p class="warning">
    <span>It's A Trap!</span>
  </p>
  <div class="image">
    <img src="img/ackbar.gif" />
  </div>
    <script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/app.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>

So, you can wrap the span in a p element that has the warning class, and then hide that p element with: $(".warning").hide(); This will hide the p element, as well as the span element inside of it.

Hope that helps!

Mehdi Amir
Mehdi Amir
658 Points

"there are no elements in your code with the warning class."

Is this : <p class="warning"> not the warning class? I thought we created a class here called warning and the ".warning" selects all the classes with that name...

Yes, earlier in the lesson there was a "p" element created with a warning class. But, in the code you posted in your question, there is no "p" element at all. There is only the "span" element, and there is no warning class on anything. The html code that i posted in the answer will allow the jquery code to work. In your posted code, what was your reason for deleting the p element?

Mehdi Amir
Mehdi Amir
658 Points

Okay thanks, I see. I didn't delete anything tbh. Not sure how it happened.

Thanks for your help!

works in chrome for me