views:

643

answers:

2

Is there a way to have this prototype js trigger only when dom is changed and not loaded?

+4  A: 

you can observe elements changing like this

$('element').observe('change',function(e){ } );

This is reserved for form elements though - textarea, select and input.

The final code would look something like:

document.observe('dom:loaded', function() {
    $('element').observe('change',function(e){
    // do something here
    });
});
seengee
Thanks, I was looking for like a dom:onChange becuase my JS skills are lacking.
Sam
no worries, please note though that you will need to nest this code within dom:loaded or window loaded code for it to correctly listen for the event. Also, please remember to accept answer/vote up if this has helped :)
seengee
As much as I appreciate you answer I still have to more research because the easiest solution would be to change loaded to another option. I guess I need to learn more js
Sam
if you mean change that "loaded" from "dom:loaded" to something else then that isnt possible
seengee
Oh, Why not? can that be changed?
Sam
thats just the syntax. the code i've given you will do what you want unless i'm missing something.
seengee
+1  A: 

The 'change' method is defined only for 'input', 'textarea' and select elements, not for general elements.

The "dom:loaded" event is a user-defined event (as far as the browser is concerned) defined by the Prototype library. I don't believe that it is usable as any kind of template for a dom:changed event.

What you are looking for are DOM mutation events, such as DomSubtreeModified (see [1]). But I don't believe these are widely supported in browsers yet.

Colin Fine