Highlight: clear() メソッド

Limited availability

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

clear()Highlight インターフェイスのメソッドで、 Highlight オブジェクトからすべての Range オブジェクトを除去します。

HighlightSet 風オブジェクトですので、これは Set.clear() を使うのと似ています。

構文

js
clear()

返値

なし (undefined)。

次のコードスニペットは、2 つの範囲を持つ新しいハイライトを作成し、それをクリアする方法を示しています。

js
const highlight = new Highlight(range1, range2);
console.log(highlight.size); // 2

highlight.clear();
console.log(highlight.size); // 0

仕様書

Specification
ECMAScript® 2026 Language Specification
# sec-set.prototype.clear

ブラウザーの互換性

関連情報