Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/angezid/advanced-mark.js/llms.txt

Use this file to discover all available pages before exploring further.

mark() highlights one or more text search terms in the DOM. It accepts a string or array of strings and wraps matches in <mark> elements (or your custom element). It supports diacritics, synonyms, wildcards, cross-element matches, the CSS Custom Highlight API, shadow DOM, iframes, and fine-grained control through filter, each, done, and noMatch callbacks.

Syntax

// Vanilla JS
const instance = new Mark(context);
instance.mark(search[, options]);

// jQuery
$(selector).mark(search[, options]);

Parameters

The search term or array of terms to highlight. Terms are automatically escaped — use markRegExp() if you need unescaped pattern matching.
options
object
Optional configuration object. All properties are optional and fall back to their defaults when omitted.

Default Options

const options = {
  element: 'mark',
  className: '',
  separateWordSearch: true,
  diacritics: true,
  exclude: [],
  caseSensitive: false,
  accuracy: 'partially',
  synonyms: {},
  ignoreJoiners: false,
  ignorePunctuation: [],
  wildcards: 'disabled',

  acrossElements: false,
  combineBy: 100,
  blockElementsBoundary: false,

  staticRanges: true,        // Highlight API
  rangeAcrossElements: true, // Highlight API
  shadowDOM: false,
  iframes: false,
  iframesTimeout: 5000,

  filter: (nodeOrArray, term, matchesSoFar, termMatchesSoFar, filterInfo) => {
    return true; // must return either true or false
  },
  each: (elementOrRange, eachInfo) => {},
  done: (total, totalMatches, termStats) => {},
  noMatch: (terms) => {},
  debug: false,
  log: window.console,
};

Usage Examples

const instance = new Mark(document.querySelector('.content'));

// Highlight a single term
instance.mark('hello world');
The abbreviation AE in parameter descriptions means the property is only present when acrossElements: true is set. MC means the count reflects matches already wrapped in elements or registered as Highlight API ranges at the time the callback fires.

Build docs developers (and LLMs) love