PerformanceElementTiming: id プロパティ
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。
id は PerformanceElementTiming インターフェイスの読み取り専用プロパティで、関連付けられた要素の 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> # dom-performanceelementtiming-id> |
ブラウザーの互換性
Loading…