<style>
.bar{background: grey}
</style>
<div>foo bar <button>baz</button></div>
<script>
document.querySelector("button").addEventListener("click", function () {
alert("I'm baz");
});
setTimeout(function () {
var d=document.querySelector("div")
d.innerHTML=d.innerHTML.replace("bar", "<span class='bar'>bar</span>");
alert("shut up, Mr. baz");
}, 3000);
</script>