targetEvent Properties

事件对象参考手册Event Object

Definition and Usage

The target event property returns the target node of the event (the node that triggered the event), such as the element, document, or window that generated the event.

Syntax

event.target
 

Example

Example

The following example gets the element that triggered the event:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function myFunction(e){
    alert(e.target);
}
</script>
</head>
<body onclick="myFunction(event)">

<p>Click a paragraph. An alert box will alert the element that triggered the event.</p>
<p><strong>Note:</strong> The target property returns the element that triggered the event, and not necessarily the element of the event listener.</p>

</body>
</html>

Try it »


事件对象参考手册Event Object Other Extensions