Skip to content

Instantly share code, notes, and snippets.

@bendc
Created January 5, 2017 13:11
Show Gist options
  • Save bendc/ef1b7055b135f7a4f3f8cead348a4576 to your computer and use it in GitHub Desktop.
Save bendc/ef1b7055b135f7a4f3f8cead348a4576 to your computer and use it in GitHub Desktop.
Web Components: hello-message-attribute
customElements.define("hello-message", class extends HTMLElement {
constructor() {
super();
const root = this.attachShadow({mode: "open"});
root.innerHTML = "Hello <slot></slot>";
}
static get observedAttributes() {
return ["name"];
}
attributeChangedCallback(name, old, change) {
this.textContent = change;
}
});
document.body.innerHTML = "<hello-message name=Jane></hello-message>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment