unmark() method
Syntax
// javascript
const instance = new Mark(context);
instance.unmark([options]);
// jQuery
$(context).unmark([options]);
Parameters:
optionsobject - Optional options:
| Option | Type | Default | Description |
|---|---|---|---|
highlightName | string 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)
|
highlight | Highlight | undefined | If 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 |
element | string | '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. |
className | string | '' | Remove only marked elements with specified class name. |
exclude | string 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).
|
shadowDOM | boolean | undefined | Whether to remove highlighting inside shadow DOMs
See shadowDOM option for more details. |
iframes | boolean | false | Whether to remove highlighting inside iframes |
iframesTimeout | number | 5000 ms | The maximum time to wait for an iframe to load before skipping |
debug | boolean | false | Whether to log messages |
log | object | console | Log messages to a specific object |
done | function | 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);