Skip to main content
Version: 3.35.1

replaceWith

The replaceWith method replaces the element with new content.

Syntax

element.replaceWith(content);
element.replaceWith(content, options);

Parameters

  • content : string

    • The content to replace the element with.
  • options : ElementRewriterOptions

    • An optional object that can have the following properties:
      • escapeHTML : boolean
        • If true, any HTML markup in content will be escaped so it is safe to insert as text.

Examples

// Assuming `e` is an Element representing <div>Hello</div>
e.replaceWith("<p>Greetings!</p>");
// Result: <p>Greetings!</p>