JavaScript and the DOM


The next feature we'd like to build is making the 'Recent Projects' clickable. When clicked, the button should show the individual projects, and when clicked again, it should hide the projects.

In order to make an element clickable, we need to write jQuery that listens to an element for a click event. jQuery can do this with an event listener function named on('click').

This function will wait for a click event, and when one occurs, it will execute a provided function. The syntax looks like this:

$('.example-class').on('click', function() {
  // execute the code here when .example-class is clicked.
  1. $('.example-class') selects an HTML element with the class example-class.
  2. .on('click', function() { ... }) adds a click listener to the selector. When it's clicked the function will execute the code within its block.
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.