event.target

JavaScript 1.2+ Nav4+ Syntax

							event.target

Description

The target property of the Event object refers to the object on which the event takes place.

Example

Listing 7.213 shows an example of how the target property can be used to determine to which object an event occurred. In the HTML document, there are three buttons. When the button is clicked, a JavaScript function catches the click event and, using the target property, tells the user which button was clicked.

Listing 7.213 Accessing the target Property
 <html> <head> <title>Using the target property of the event object</title> </head> <body> <script language = "JavaScript"> <!--Hide // informs the user which mouse button was pressed function whichButton(evnt){ window.captureEvents(evnt.CLICK); ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.