Calling function based on changing dom

I rewrote some of my code based on the fact that it is not possible to check if the javascript variable is changing. But how would I do this with the dom element? For example,

<div id='foo'>123</div>
<script>
$('#foo').html('456');
// function gets fired since #foo changed.
</script>

I tried

$("#foo").change(function () {
      alert('change!');
    })
    .change();

but no luck.

+5
source share

All Articles