Code has been added to clipboard!

jQuery Event Target: Return the Element Which Triggered an Event

Reading time 1 min
Published Jan 8, 2018
Updated Sep 25, 2019

jQuery Event Target: Main Tips

  • The event.target property is used to return the element that invoked a specified event.
  • The event target jQuery function handles event bubbling.

Usage of event.target

The event.target jQuery property is used to return the element that triggered the specified event. We recommend comparing jQuery event target to this to check whether event bubbling occurs.

Example
$("p, button").click((event) => {
    $("div").html("Was triggered by button " + event.target.nodeName + " element.");
});

The example above shows which HTML element triggers the onclick event.

Note: use event.target jQuery property for event delegation. It is the process of assigning a parent as the listener for events.

Latest Udacity Coupon Found:

Verified STAFF PICK

75% OFF COURSES

Udacity Black Friday Offer

The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!

Expiration date: 30/01/2021
3176 People Used
Only 97 Left
Rating
5.0