var element = document.getElementById('div');
element.addEventListener('DOMSubtreeModified', myFunction);
function myFunction(e) {
console.log(element.innerHTML);
}
setTimeout(function(){
element.innerHTML = 'Hello World!';
}, 1000);
setTimeout(function(){
element.innerHTML = 'Hello Space!';
}, 2000);
참조
https://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=qna_html&wr_id=281733