views:

78

answers:

2

I want to write a Firefox add-on.

I need to monitor the contents of a DIV element.

Is there a way to put a hook or subscribe to the modification of a certain HTML element?

I don't want to poll the contents of the DIV (per say) every second, would be nice to be notified when it is changed.

Thank you.

A: 

Instead of writing an extension have you thought about writing a Greasemonkey script? Much easier and no compiler needed. I've also seen programs that can convert scripts to XPI's but haven't tried them.

http://www.greasespot.net/

Chris Haas
Thank you for the suggestion, I forgot about Greasemonkey.But still, would be nice to know how to make a hook in JS.
Alexandru Luchian
+2  A: 

Found how to do this!

function onLoadDoThings(){  
 document.getElementById('changingDiv').addEventListener('DOMSubtreeModified',function(){
    alert(document.getElementById('changingDiv').innerHTML);
  }
,false);
}
Alexandru Luchian