Back to Content

Highlight: clear() method

files/en-us/web/api/highlight/clear/index.md

latest970 B
Original Source

{{APIRef("CSS Custom Highlight API")}}

The clear() method of the {{domxref("Highlight")}} interface removes all the {{domxref("Range")}} objects from a Highlight object.

Highlight is a {{jsxref("Set")}}-like object, so this is similar to using {{jsxref("Set.clear()")}}.

Syntax

js-nolint
clear()

Parameters

None.

Return value

None ({{jsxref("undefined")}}).

Examples

The code snippet below shows how to create a new highlight with two ranges, and then clear it:

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

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

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also