Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the exact difference between currentTarget property and target property in JavaScript

Tags:

javascript

Can anyone please tell me the exact difference between currentTarget and target property in JavaScript events with example and which property is used in which scenario?

like image 885
Valli69 Avatar asked Apr 10 '12 09:04

Valli69


People also ask

What is the difference between target and currentTarget in Javascript?

target is the element that triggered the event (e.g., the user clicked on) currenttarget is the element that the event listener is attached to.

What is the difference between event target and event currentTarget properties?

target is the root element that raised the event. currentTarget is the element handling the event.

What does currentTarget do in Javascript?

The currentTarget read-only property of the Event interface identifies the current target for the event, as the event traverses the DOM. It always refers to the element to which the event handler has been attached, as opposed to Event.

What is Javascript target?

Definition and Usage. The target event property returns the element that triggered the event. The target property gets the element on which the event originally occurred, opposed to the currentTarget property, which always refers to the element whose event listener triggered the event.


1 Answers

Events bubble by default. So the difference between the two is:

  • target is the element that triggered the event (e.g., the user clicked on)
  • currentTarget is the element that the event listener is attached to.
like image 79
Griffin Avatar answered Oct 03 '22 23:10

Griffin