CSS Custom Highlight API
The Highlight() constructor returns a newly created
Highlight object which can hold a collection of AbstractRange objects to be styled using the css_custom_highlight_api.
Syntax
new Highlight()
new Highlight(range)
new Highlight(range1, range2, /* …, */ rangeN)
Parameters
range1, …,rangeN- : One or more initial AbstractRange objects to add in the new highlight.
Return value
A new Highlight object.
Examples
The example code below demonstrates how to create an empty highlight object, and then add ranges to it:
const highlight = new Highlight();
highlight.add(range1);
highlight.add(range2);
The example code below demonstrates how to create a new highlight object and add ranges to it during instantiation:
const highlight = new Highlight(range1, range2);
Specifications
Browser compatibility
See also
- css_custom_highlight_api
- CSS custom highlight API module
- CSS Custom Highlight API: The Future of Highlighting Text Ranges on the Web
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
