JSFiddle - React, Tailwind, and code Playground

by prometh

JavaScript

const callback = mutations => alert(mutations);

const div = document.createElement('div');
div.innerText = 'text';
document.body.appendChild(div);

const b = document.createElement('b');
b.innerText = 'text';
div.appendChild(b);

const i = document.createElement('b');
i.innerText = 'text';
div.appendChild(i);

new MutationObserver(callback).observe(div, {characterData:true, childList:true/*, subtree:true*/});

b.firstChild.data = 'changed'; // only want this one to be observed
i.firstChild.data = 'changed';