Hasan A Yousef
Hasan A Yousef

Reputation: 24948

DOM change listener in Dart lang

I want to have a script execute when the contents of a DIV change, in a different way, I want to listen to specific nodes/child changes, I found something in JavaScript called "DOMSubtreeModified" at this fiddle,

$("#someDiv").bind("DOMSubtreeModified", function() {
    alert("tree changed");
});

is there something similar in DART?

Upvotes: 1

Views: 335

Answers (1)

Hasan A Yousef
Hasan A Yousef

Reputation: 24948

Thanks @Gunter Zochbauer, Along with the recommended sites you gave, I found this about MountainObserver in DART, and the below code worked perfectly for me :)

main(){
     ...
     Element myDiv = querySelector('#my-element');
     var observer = new MutationObserver((mutations, _) {
          mutations.forEach((mutation) {
               print('number of direct nodes here are: ${myDiv.nodes.length}');;
         });
     });
     observer.observe(myDiv, childList: true); 
     ....
  }

in the index.html, I've:

<div id='my-element'></div>

Upvotes: 4

Related Questions