For those times you need to apply persistent DOM changes on top of HTML you don’t control.

Demo

import mutate from "dom-mutator"

// Start mutating
const mutation = mutate.html(".demo", html => html.toUpperCase());

// Stop mutating
mutation.revert();
a

Usage

yarn add dom-mutator OR npm install --save dom-mutator.

import mutate from "dom-mutator";

mutate.html(".demo", html => html.toUpperCase());

mutate.classes("div.greeting", classes => classes.add("new-class"));

mutate.attr(".get-started", "title", (oldVal) => "This is my new title attribute");

And there’s even a declarative option if you don’t want to use callbacks:

import mutate from "dom-mutator";

mutate.declarative({
  selector: "h1",
  action: "set",
  attribute: "html",
  value: "hello world"
});

attribute can be “html” or any valid html attribute (title, class, href, etc.).

action can be “set” or “append”. If the attribute is “class”, there is an additional “remove” action you can use.