Event.type

typeEvent インターフェイスの読み取り専用プロパティで、イベントの種別を表す文字列を返します。イベントが構築されると設定され、この名前は click, load, error のような特定のイベントを参照するためによく使用されます。

Event の種別を表す文字列です。

この例は、キーボードのキーを押すか、マウスボタンをクリックするとイベント種別をログに出力します。

HTML

<p>キーを押すか、マウスをクリックしてください。</p>
<p id="log"></p>

JavaScript

function getEventType(event) {
  const log = document.getElementById('log');
  log.innerText = event.type + '\n' + log.innerText;
}

// キーボードイベント
document.addEventListener('keydown', getEventType, false);  // first
document.addEventListener('keypress', getEventType, false); // second
document.addEventListener('keyup', getEventType, false);    // third

// マウスイベント
document.addEventListener('mousedown', getEventType, false); // first
document.addEventListener('mouseup', getEventType, false);   // second
document.addEventListener('click', getEventType, false);     // third

結果

仕様書

Specification
DOM Standard
# ref-for-dom-event-type④

ブラウザーの互換性

BCD tables only load in the browser

関連情報