Remove highlighted mark elements created by advanced-mark.js, normalize text nodes, or clear CSS Custom Highlight API ranges from the HighlightRegistry.
Use this file to discover all available pages before exploring further.
unmark() removes all mark elements created by advanced-mark.js and normalizes text nodes back to their original state. When using the CSS Custom Highlight API, it removes the registered StaticRange/Range objects from the HighlightRegistry instead of modifying the DOM. Use unmark() before calling mark() again to avoid stacking highlights on top of previous ones.
The element name to target for removal. Must match the element option you used when calling mark(), markRegExp(), or markRanges().Use '*' to remove any element that carries a data-markjs attribute, regardless of tag name — useful when highlights were created using different element types in the same context.
When provided, only mark elements with this specific CSS class are removed. Elements without the class are left in place. Useful for selectively clearing one group of highlights while keeping others.
A CSS selector string or array of selectors for DOM subtrees that should be skipped during the removal operation. Mark elements inside excluded subtrees are left untouched.
If you used the CSS Custom Highlight API with acrossElements: true and rangeAcrossElements: true, ranges that overlap an excluded element cannot be selectively excluded — the entire range will be removed.
A browser Highlight object. When provided, the library skips DOM unwrapping entirely and only removes ranges from the HighlightRegistry. The element and className options are ignored in this mode.This is a performance optimization: it avoids iterating the DOM when you know the context only contains Highlight API ranges and no wrapped elements.
The name or array of names of Highlight objects whose ranges should be cleared from CSS.highlights. This corresponds to the highlightName you used when calling a marking method.
// Clear a single named highlightinstance.unmark({ highlightName: 'search-results' });// Clear multiple named highlights at onceinstance.unmark({ highlightName: ['search-results', 'current-match'] });
const instance = new Mark(document.querySelector('.content'));// Remove all default <mark> elementsinstance.unmark();
When the highlight option is provided, unmark()only removes ranges from the HighlightRegistry — it does not unwrap any DOM elements. Use this when you are exclusively using the CSS Custom Highlight API and want to avoid an unnecessary DOM traversal.
To unmark elements that were marked with a custom tag (e.g. element: 'span'), you must pass the same tag name to unmark(). Alternatively, pass element: '*' to remove any element carrying the data-markjs attribute, regardless of tag name. Note that using '*' applies broadly — only use it when you are certain all data-markjs elements in the context should be removed.