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
2009-12-15 14:17:01
Thanks, I was looking for like a dom:onChange becuase my JS skills are lacking.
Sam
2009-12-15 14:19:11
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
2009-12-15 14:21:04
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
2009-12-15 14:23:50
if you mean change that "loaded" from "dom:loaded" to something else then that isnt possible
seengee
2009-12-15 14:24:54
Oh, Why not? can that be changed?
Sam
2009-12-15 14:48:18
thats just the syntax. the code i've given you will do what you want unless i'm missing something.
seengee
2009-12-15 15:19:46
+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
2009-12-15 15:25:02