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) Creating a Simple Drawing Application Perform: Part 2

Using if css("display") == "none" to toggle display

I tried to use a simple if statement to toggle the display, but it doesn't work. Code snippet below:

$("#revealColorSelect").click(function(){ if($("#colorSelect").css("display")=="none") { $("#colorSelect").show(); } else {$("#colorSelect").hide();} });

The problem here is that it doesn't appear that $("#colorSelect").css("display") is actually pulling the value of the the display property in CSS.

Any ideas why this doesn't work the way I think it should?

1 Answer

jobbol
seal-mask
.a{fill-rule:evenodd;}techdegree
jobbol
Full Stack JavaScript Techdegree Student 16,610 Points

I double checked the .css() function for jQuery. It does indeed return the value of whatever property you give it.

I also wrote up an app to test your code snippet. It appears to be working. https://jsfiddle.net/uchhmgqy/1/

Perhaps it's something else on your end you overlooked? Isolate and post your code. I'll see what I can do.

You're right that it works correctly. After refreshing my browser the code works.