Highlight: clear() method
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("CSS Custom Highlight API")}}
The **clear()** method of the {{domxref("Highlight")}} interface removes all the {{domxref("AbstractRange")}} 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); // 0Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- {{domxref("css_custom_highlight_api", "The CSS Custom Highlight API", "", "nocode")}}
- CSS Custom Highlight API: The Future of Highlighting Text Ranges on the Web