Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics (2014) Creating a Simple Drawing Application Perform: Part 2

Aaron Selonke
Aaron Selonke
10,323 Points

Show() 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

Show 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.


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.