JSFiddle - React, Tailwind, and code Playground

by Gabriel Z

HTML

<div id="text" contentEditable>
    Type something in here.
  </div>

JavaScript

var text = document.querySelector("#text");
var observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
      var entry = {
        mutation: mutation,
        el: mutation.target,
        value: mutation.target.textContent,
        oldValue: mutation.oldValue
      };
      console.log("Recording mutation:", entry);
    });
  });

observer.observe(text, {
    attributes: true,
    childList: true,
    characterData: true,
    characterDataOldValue: true,
    subtree: true
});