mazey
    Preparing search index...

    Function extractElementText

    • Extract text from a cloned element without modifying the original DOM. Images can be replaced by their alt text, selected descendants can be removed, and whitespace can be normalized before returning the text.

      Invalid exclusion selectors are ignored.

      Usage:

      import { extractElementText } from "mazey";

      const element = document.querySelector(".message");
      const text = extractElementText(element, {
      excludeSelector: ".message-actions",
      });

      Parameters

      • element: Element

        Element whose cloned contents are read.

      • options: {
            excludeSelector?: string;
            normalizeWhitespace?: boolean;
            replaceImagesWithAlt?: boolean;
        } = {}
        • OptionalexcludeSelector?: string

          Selector for descendants to remove from the clone.

        • OptionalnormalizeWhitespace?: boolean

          Whether whitespace is collapsed and trimmed. Defaults to true.

        • OptionalreplaceImagesWithAlt?: boolean

          Whether images with an alt attribute are replaced by that text. Defaults to true.

      Returns string

      Extracted text from the cloned element.

      Browser only.