JSFiddle - React, Tailwind, and code Playground

HTML

<div id="box"></div>
<button onclick="addit()">Add</button>
<button onclick="removeit()">Remove</button>

JavaScript

var box = document.getElementById("box");

function addit() {
box.insertAdjacentHTML('afterbegin', '<span id="elm" data-added="yes">element</span>');
}

function removeit() {
document.getElementById("elm").remove();
}

new MutationObserver((mutations) => {
         for (let mutation of mutations) {
          if (mutation.type === 'childList' && mutation.addedNodes[0].dataset.added) {
           console.log('added');
          }
         }
        }).observe(box, {childList: true});