TouchList: length プロパティ

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

length は読み取り専用のプロパティで、指定された TouchList の項目(タッチポイント)の数を示します。

touchList のタッチポイントの数です。

このコード例では、TouchList インターフェイスの item メソッドと length プロパティの使い方を示しています。

js
const target = document.getElementById("target");

target.addEventListener(
  "touchstart",
  (ev) => {
    // この touchstart イベントが対象要素で始まった場合、touch を
    // targetTouches リストの最初の項目に設定します。そうでない
    // 場合は、touch リストの最初の項目に touch を設定します。
    const touch =
      ev.targetTouches.length >= 1
        ? ev.targetTouches.item(0)
        : ev.touches.item(0);
  },
  false,
);

仕様書

Specification
Touch Events
# dom-touchlist-length

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
length

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Has more compatibility info.