Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.observe('dom:loaded', function() {

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

like image 326
thenengah Avatar asked Dec 15 '09 14:12

thenengah


Video Answer


2 Answers

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
    });
});
like image 171
robjmills Avatar answered Sep 23 '22 23:09

robjmills


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.

like image 31
Colin Fine Avatar answered Sep 25 '22 23:09

Colin Fine