views:

113

answers:

3

Is it possible to fire an event when the innerHTML of a changes?

I am using YUI 3.

Thanks!

A: 

There is no out of the box onchange event for divs. If you want this you are going to have write this yourself (with a timer and storing whats the current value etc).

I would however try to take it a step back and call a method when you change the innerValue of that div to take care of ... w/e.

Fabian
I don't have control over the code which changes the innerHTML. That's why I want fire the event.
Sudar
+1  A: 

Use a setter:

myDiv.__defineSetter__("innerHTML",
  function(newHTML) {
    ...
  }
);

https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Working_with_Objects#Defining_Getters_and_Setters

Delan Azabani
I found two problems with this approach.1) The function get's called, but I am not able to actually set the innerHTML now. if I call this.innerHTML = newHTML, then the method get's called infinitely.2) Doesn't seem to work in Safari and Chrome
Sudar
+1  A: 

I think Fabian's right in that you'll need to user a timer and compare the value.

That being said, the right way to do this in YUI3 would be to define a synthetic DOM event using later.

Tivac