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 trialJohn Gu
6,891 PointsUsing 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
Full Stack JavaScript Techdegree Student 17,885 PointsI 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.
John Gu
6,891 PointsJohn Gu
6,891 PointsYou're right that it works correctly. After refreshing my browser the code works.
jobbol
Full Stack JavaScript Techdegree Student 17,885 Pointsjobbol
Full Stack JavaScript Techdegree Student 17,885 PointsAh, I've made that before. It's okay. :)