jQuery click()

Let's invoke a function on the jQuery click() event!
We're completing these tasks in Submlime and the console.

This is an example of a click function:

    $("mySelector").click(function(e) {
        // e is the click data
        e.preventDefault(); // this prevents the defaul click event from occuring (page loading/moving)
        // click occured
    });

The button abovce has an ID of button.

  1. Open the js/008.5-jquery.js file in Sublime Text. It should have a ready() function.
  2. Inside the ready() function, add the function above using the selector #button.
    • Hint: Add the new code at the bottom of the ready() function. Right below the comment // click function here.
  3. Add the code console.log("button clicked"); inside the click handler of the click function.
    • Hint: Add your code after the // click occured
  4. Save the js/008.5-jquery.js file and refresh this page in your browser.
  5. Click on the button above. In the console, you should see button clicked.

jQuery Docs click()