Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Use a Mutation Observer to tell when an element has been attached to the DOM" />
<meta charset=utf-8 />
<title>Polymer</title>
</head>
<body>
  <script src="http://www.polymer-project.org/platform.js"></script>
  <link rel="import"
        href="http://www.polymer-project.org/components/polymer/polymer.html">
  
  <polymer-element name="x-foo" noscript>
    <template>
      <h1>Hello from x-foo</h1>
    </template>
  </polymer-element>
  
  <script>
    var target = document.body;
    
    // create an observer instance
    var observer = new MutationObserver(function(mutations) {
      mutations.forEach(function(mutation) {
        if (mutation.addedNodes[0].nodeName.toLowerCase() == 'x-foo') {
          console.log('x-foo attached. ready to test');
        }
      });    
    });
    
    // configuration of the observer:
    var config = { childList: true };
    
    // pass in the target node, as well as the observer options
    observer.observe(target, config);
    
    // add something to target
    var xfoo = document.createElement('x-foo');
    target.appendChild(xfoo);
    
    // later, you can stop observing
    // observer.disconnect();
  </script>
  
</body>
</html>
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
robdodsonpro
0viewers