<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="container"></div>
<script>
div=document.createElement("div")
div.innerHTML="foo"
observer=new MutationObserver(function(mutations){
mutations.forEach(function(mutation){if(mutation.target.id==="container") alert("my script is running")})
})
observer.observe(container, {childList: true})
setTimeout(function(){container.appendChild(div)}, 3000)
</script>
</body>
</html>