JavaScript and the DOM


Let's add one more feature: when we click the 'Recent Projects' button the background color and text color should change.

We can toggle a CSS class with a jQuery function named toggleClass. The syntax looks like this:

  1. .toggleClass is a function that will toggle a CSS class on the jQuery selector it's connected to. If the element has the class applied to it, toggleClass will remove it, and if the element does not have the class, it will add it.

  2. 'active' is the class that we will toggle on and off. Notice that toggleClass does not require us to include the period before 'active' since it's already expecting a CSS class.

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.