Skip to content

Instantly share code, notes, and snippets.

@sbatson5
Last active February 24, 2020 21:39
Show Gist options
  • Save sbatson5/77e507ea2733f30d512a992b936d3389 to your computer and use it in GitHub Desktop.
Save sbatson5/77e507ea2733f30d512a992b936d3389 to your computer and use it in GitHub Desktop.
Step 3
class CandidateImage extends HTMLElement {
connectedCallback() {
this.shadow = this.attachShadow({ mode: 'open' });
// Create an image
const image = new Image();
image.src = 'https://cdn-candidates.com/bernie.jpg';
// We can use appendChild just like we do the normal document
this.shadow.appendChild(image);
}
}
/**
* Register our custom element
*/
window.addEventListener('DOMContentLoaded', () => {
customElements.define('candidate-image', CandidateImage);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment