Code has been added to clipboard!

Use event currentTarget to Return Current Target of Events

Reading time 1 min
Published Dec 29, 2017
Updated Sep 25, 2019

jQuery event currentTarget: Main Tips

  • After traversing the DOM, jQuery event currentTarget property specifies the element to which an event is applied.
  • This method is the opposite of event.target since it returns the element that had the event handler assigned.

What Does currentTarget Represent

The jQuery currentTarget has the same purpose as this selector. It returns the current target (DOM element) for the event.

In the code example below, an alert message is set to only return True if the jQuery event currentTarget matches this, or when <h3> is clicked:

Example
$("h1, h2, h3").click((event) => {
  alert(event.currentTarget.nodeName === "H3");
});

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: 18/01/2021
3176 People Used
Only 97 Left
Rating
5.0