Key Concepts

Review core concepts you need to learn to master this subject

jquery on method

//The .on() method adds a 'click' event to the '#login' element. When the '#login' element is clicked, the callback function will be executed, which reveals the '#login-form' to the user. $('#login').on('click', () => { $('#login-form').show(); });

The jQuery .on() method adds event listeners to jQuery objects and takes two arguments: a string declaring the event to listen for (such as ‘click’), and the event handler callback function. The .on() method creates an event listener that detects when an event happens (for example: when a user clicks a button), and then calls the event handler callback function, which will execute any defined actions after the event has happened.

jquery on event listeners

//The .on() method adds a 'click' event to the '#login' element. When the '#login' element is clicked, the callback function will be executed, which reveals the '#login-form' to the user. $('#login').on('click', () => { $('#login-form').show(); });

jQuery .on() event listeners support all common browser event types such as mouse events, keyboard events, scroll events and more.

jquery on method chaining

//The .on() method adds a 'click' event to the '#login' element. When the '#login' element is clicked, the callback function will be executed, which reveals the '#login-form' to the user. $('#login').on('click', () => { $('#login-form').show(); });

jQuery .on() event listener methods can be chained together to add multiple events to the same element.

jquery event object

//The .on() method adds a 'click' event to the '#login' element. When the '#login' element is clicked, the callback function will be executed, which reveals the '#login-form' to the user. $('#login').on('click', () => { $('#login-form').show(); });

In a jQuery event listener, an event object is passed into the event handler callback when an event occurs. The event object has several important properties such as type (the event type) and currentTarget (the individual DOM element upon which the event occurred).

jquery event.currentTarget attribute

//The .on() method adds a 'click' event to the '#login' element. When the '#login' element is clicked, the callback function will be executed, which reveals the '#login-form' to the user. $('#login').on('click', () => { $('#login-form').show(); });

In a jQuery event listener callback, the event.currentTarget attribute only affects the individual element upon which the event was triggered, even if the listener is registered to a group of elements sharing a class or tag name.

Mouse Events
Lesson 1 of 1
  1. 1
    The jQuery library provides a collection of methods that serve one of two purposes. - To listen for an event — an event (e.g. clicking a button) is something the user does to trigger an act…
  2. 2
    Another popular jQuery event listener is mouseenter. The mouseenter event triggers a callback function when a user enters the area that a targeted element occupies. To listen for a mouse enter eve…
  3. 3
    One issue with the behavior we added to our Sole Shoes website in the last exercise is that the menu remains in the DOM after the mouse leaves the menu area. The mouseleave event listener can dete…
  4. 4
    jQuery also allows us to chain multiple methods. Instead of re-declaring the HTML element you’re selecting, you can append one event to another. Let’s see how we can use chaining to add hover fun…
  5. 5
    Have you noticed in our Sole Shoes website that when you mouse over one photo, all of the images zoom. That’s because .product-photo is a class on all the product photos. One way to solve this iss…
  6. 6
    In this lesson, you learned a few of the most common mouse events in the jQuery library. - Event handlers are comprised of an event listener and a callback function. An event listener specifies th…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo