JavaScript and the DOM


When we click on a 'Recent Projects' button, the projects show. Next, let's hide the projects if we click the 'Recent Projects' button again.

jQuery provides a function named toggle that is helpful in this situation. toggle will hide or show an element, each time it is triggered. The syntax looks like this:

  1. toggle can be called directly on an jQuery selector.
  2. When toggle is executed, it will hide or show the element that the selector points to. If the element is currently hidden, toggle will show the element, and vice versa.
Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.