Skip to content

Instantly share code, notes, and snippets.

@simondahla
Created June 10, 2014 14:59
Show Gist options
  • Save simondahla/0c324ba8e6ed36055787 to your computer and use it in GitHub Desktop.
Save simondahla/0c324ba8e6ed36055787 to your computer and use it in GitHub Desktop.
var myElement = document.getElementById('IDoftheDIV');
if(window.addEventListener) {
// Normal browsers
myElement.addEventListener('DOMSubtreeModified', contentChanged, false);
} else
if(window.attachEvent) {
// IE
myElement.attachEvent('DOMSubtreeModified', contentChanged);
}
function contentChanged() {
// this function will run each time the content of the DIV changes
}
@arkzameen
Copy link

Many thanks for this. Worked like a charm! I am using Stimulus JS in rails. If anybody else doing the same lands here, include this code in connect() function of your controller and use contentChanged as this.contentChanged().

@andremalveira
Copy link

Perfeito, era o que eu estava procurando, muito obrigado!

@andreaskoeszegi
Copy link

Thank you so much!
Great code

@EvertonBrzozowyAlves
Copy link

Thank you. It helped me today!

@Soumen-CC
Copy link

good, It helped me.

@angelxaces
Copy link

It works...

...and if the the change your listening for involves a list being iterated, you get to watch it work ' + list.length-1 + " times in rapid succession!

@mssuath
Copy link

mssuath commented Jul 11, 2024

Thank you very much work fine and simple and clean

@ivan19940106
Copy link

You saved me! Thank you so much!!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment