unmark() method

Syntax

// javascript
const instance = new Mark(context);
instance.unmark([options]);
// jQuery
$(context).unmark([options]);

Parameters:

  • options object - Optional options:
OptionTypeDefaultDescription
highlightNamestring or string[] 'advanced-markjs'A name or an Array of names of the Highlight object(s) from which StaticRange/Range objects should be deleted (according with the exclude option)
highlightHighlight undefinedIf a highlight object is specified, the library do not removed any mark elements; element and className options are ignored
Note that the Highlight object served as boolean:
1. to prevent unwrapping existing marked elements
2. to avoid unnecessary iteration over DOM searching for non-existing marked elements
elementstring 'mark'Specifies marked elements to remove.
Note: if other than the default marked element is used, e.g. span, it must be also specified in the unmark() method. It is also possible to use \* in case of using different marked elements to unmark in one run. A mark.js library uses a default selector \*[data-markjs] but it is not safe to apply to all HTML elements.
classNamestring ''Remove only marked elements with specified class name.
excludestring or string[] []A string or an array of selectors. Specifies the DOM elements that should be excluded from removing highlighting.
Important: if highlighting is done using the Highlight API with acrossElements and rangeAcrossElements options and the element you want to exclude is inside a range, there is no possibility to exclude this element (the whole range will be removed).
shadowDOMboolean undefinedWhether to remove highlighting inside shadow DOMs

See shadowDOM option for more details.

iframesboolean falseWhether to remove highlighting inside iframes
iframesTimeoutnumber 5000 msThe maximum time to wait for an iframe to load before skipping
debugboolean falseWhether to log messages
logobject consoleLog messages to a specific object
donefunction A callback after highlighting was removed
done: () => {}

It has no parameters.

Example with default options values
const options = {
    highlight: undefined,
    highlightName: 'advanced-markjs',
    element: 'mark',
    className: '',
    shadowDOM: false,
    iframes: false,
    iframesTimeout: 5000,
    done: () => {},
    debug: false,
    log: window.console
};

JavaScript:

var instance = new Mark(document.querySelector('selector'));
instance.unmark(options);

jQuery:

$('selector').unmark(options);