title: How to tell when the DOM is ready in Dart?
body: <p>I want to get some information about some DOM elements after the page is ready, but I haven't figured out how to tell when this is.  I've tried using <code>document.on.contentLoaded</code> and <code>document.on.readyStateChange</code>, but neither seem to work.  In the following code, <code>onContentLoaded()</code> and <code>onReadyChanged()</code> never get called.</p>
  
  <pre><code>class WhiteTrace {
  
    WhiteTrace() {    
    }
  
    void onContentLoaded(Event e) {
      print("onContentLoaded");
      // This never gets called 
    }
  
    void onReady() {
      print("onReady");
      // Do stuff
    }
  
    void onReadyChanged(Event e) {
      print("onReadyStateChanged");
      // This never gets called
      if (document.readyState == "complete") {
        onReady();
        document.on.readyStateChange.remove(onReadyChanged);
      }
    }
  
    void onResize(Event e) {
      // Do stuff
    }
  
    void run() {
      write("Hello World!");
      document.on.contentLoaded.add(onContentLoaded);
  
      window.on.resize.add(onResize);
  
      document.on.readyStateChange.add(onReadyChanged); 
      print("readyState: " + document.readyState);
      if (document.readyState == "complete") {
        document.on.readyStateChange.remove(onReadyChanged);
        onReady();
      }
    }
  
    void write(String message) {
      // the HTML library defines a global "document" variable
      document.query('#status').innerHTML = message;
    }
  }
  
  void main() {
    new WhiteTrace().run();
  }
  </code></pre>