event.targetReturns: Element
Description: The DOM element that initiated the event.
version added: 1.0event.target
The target
property can be the element that registered for the event or a descendant of it. It is often useful to compare event.target
to this
in order to determine if the event is being handled due to event bubbling. This property is very useful in event delegation, when events bubble.
Examples:
Display the tag's name on click
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
|
Demo:
Implements a simple event delegation: The click handler is added to an unordered list, and the children of its li children are hidden. Clicking one of the li children toggles (see toggle()) their children.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
|