Event: target プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
メモ: この機能はウェブワーカー内で利用可能です。
target
は Event
インターフェイスの読み取り専用プロパティで、イベントが配信されたオブジェクトへの参照です。これは、イベントのバブリングまたはキャプチャ段階でイベントハンドラーが呼び出されたときの Event.currentTarget
とは異なります。
値
関連する EventTarget
です。
例
event.target
プロパティは、イベントデリゲーションを実装するために使用できます。
js
// リストの作成
const ul = document.createElement("ul");
document.body.appendChild(ul);
const li1 = document.createElement("li");
const li2 = document.createElement("li");
ul.appendChild(li1);
ul.appendChild(li2);
function hide(evt) {
// evt.target はクリックされた <li> 要素を参照しています。
// これはこのコンテキストで親である <ul> を参照している evt.currentTarget とは異なります。
evt.target.style.visibility = "hidden";
}
// リストにリスナーを接続します
// <li> がクリックされた時に発行されます。
ul.addEventListener("click", hide, false);
仕様書
Specification |
---|
DOM # ref-for-dom-event-target③ |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
target |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.