PerformanceElementTiming: id プロパティ

Limited availability

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

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。

idPerformanceElementTiming インターフェイスの読み取り専用プロパティで、関連付けられた要素の id を返します。

文字列です。

id の使用

この例では<img>要素にelementtiming属性を追加して監視しています。 PerformanceObserver"element" 型のパフォーマンス項目をすべて取得するために登録され、オブザーバー作成前のデータにアクセスするために buffered フラグが使用されます。これはコンソールに myImage とログ出力します。これは画像要素の id です。

html
<img
  src="image.jpg"
  alt="a nice image"
  elementtiming="big-image"
  id="myImage" />
js
const observer = new PerformanceObserver((list) => {
  list.getEntries().forEach((entry) => {
    if (entry.identifier === "big-image") {
      console.log(entry.id);
    }
  });
});
observer.observe({ type: "element", buffered: true });

仕様書

Specification
Element Timing API
# ref-for-dom-performanceelementtiming-id

ブラウザーの互換性