JSFiddle - React, Tailwind, and code Playground

by ermakovnikolay

HTML

<ul id="s">

<li>asas</li>
<li>asas212</li>
</ul>

<button id="sas">
wewew
</button>

JavaScript

// create new MutationObserver object and pass callback to execute if mutation happens
var observer = new MutationObserver(function(MutationRecord) {
    // get array of added li objects, use MutationRecord[0].addedNodes[0] for a single one
    var newLiAdded = MutationRecord[0].addedNodes;
    alert('add')
    // ... code you want to execute after li was added
});

// specify what element to watch for mutations
var target = document.querySelector('#s');

// specify what mutation to watch
var config = {
    childList: true 
};

// start watching
observer.observe(target, config);

$('#sas').click(function(){
   $('#s').append('<li>new</li>')
})