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 trialAaron Selonke
10,323 PointsShow() vs Toggle()
When doing Andy's courses I usually pause the video and try to puzzle out what he wants before watching how to do it.
I came up with this, to display the color select... $("#revealColorSelect").click(function(){ $("#colorSelect").show(); });
He uses the toggle() method. What's the difference between show() and toggle()?
Why do people on stack say that toggle() is depreciated while its not depreciated in the documentation?
2 Answers
Siddhant Mehta
Courses Plus Student 478 PointsShow holds only single function i.e. to show hide element while toggle perform both show and hide function. Eg:- when an element is hide toggle will perform show function.
Asia Chan
11,007 Points$("#revealColorSelect").click(function(){
$("#colorSelect").show();
});
Once you click on "New Color" you can't hide it anymore. Toggle allows it to hide since in the first load it is hidden, good UI experience should allow for the user to go back to the original state of the UI. And .toggle()
is still on the jQuery api.