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

CSS jQuery Basics (2014) Introduction to jQuery Hiding and Showing Elements With jQuery

I am unable to hide the element using hide() in workspace

Here is my snapshot https://w.trhou.se/pfhficoy40

4 Answers

Adrian Randall
Adrian Randall
4,807 Points

Wrap it in document ready..the DOM element probably isnt loaded when that JS is called

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

Tim Knight
Tim Knight
28,888 Points

Vamsi,

You want to make sure you jQuery code isn't running until the document is fully loaded, that's probably what's happening here.

So instead of just:

$(".warning").hide()

Try this:

$(function () {
  $(".warning").hide();
});
Adrian Randall
Adrian Randall
4,807 Points

@Tim isn't that just an anonymous function?

I could be wrong but I always check the document is ready

Tim Knight
Tim Knight
28,888 Points

In this case it's really just shorthand for the domready check.

See: http://www.unseenrevolution.com/jquery-document-ready-shorthand/

Adrian Randall
Adrian Randall
4,807 Points

Tim Knight - I did not know that, been doing the doc ready for years!

Cheers

it looks like you are forgetting semicolon