Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <title>Changes to slot children should trigger slotchange</title>
  <script src="https://rawgit.com/webcomponents/webcomponentsjs/v1.0.0-rc.6/webcomponents-lite.js"></script>
  <script>
    class TestElement extends HTMLElement {
      constructor() {
        super();
        // Create a shadow root with a slot.
        const root = this.attachShadow({ mode: 'open' });
        root.innerHTML = `<slot></slot>`;
        // Listen for slotchange.
        const slot = root.querySelector('slot');
        slot.addEventListener('slotchange', event => {
          console.log(event.type);
        });
        // Add default content to the slot.
        const text = new Text('Hello');
        slot.appendChild(text);
      }
    }
    customElements.define('test-element', TestElement);
  </script>
</head>
<body>
  <p>
    When this page loads, it should log a slotchange event to the console.
  </p>
  <test-element></test-element>
</body>
Output 300px

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

Dismiss x
public
Bin info
Jan_Miksovskypro
0viewers