Created
March 29, 2020 15:12
-
-
Save rudifa/32c9fd5b3f9bc5807bbdf37bcfa77a7d to your computer and use it in GitHub Desktop.
// source https://jsbin.com/yidesawide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| - | |
| <html> | |
| <body> | |
| <style> | |
| body { | |
| font-family: monospace; | |
| } | |
| h1 { color: pink; } | |
| </style> | |
| <h1>Hello first world!</h1> | |
| <cool-heading> | |
| <h1>Hello cool world!</h1> | |
| </cool-heading> | |
| <template> | |
| <style> | |
| h1 { color: green; } | |
| </style> | |
| <h1>Hello again!</h1> | |
| </template> | |
| <script> | |
| // your code will go here | |
| class CoolHeading extends HTMLElement { | |
| constructor() { | |
| super(); | |
| this.addEventListener('click', () => { | |
| this.style.color = 'red'; | |
| }); | |
| } | |
| connectedCallback() { | |
| console.log('CoolHeading connected!'); | |
| this.style.color = 'blue'; | |
| const template = document.querySelector('template'); | |
| const clone = document.importNode(template.content, true); | |
| this.attachShadow({ mode: 'open' }); | |
| this.appendChild(clone); | |
| } | |
| } | |
| customElements.define('cool-heading', CoolHeading); | |
| </script> | |
| <script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
| - | |
| <html> | |
| <body> | |
| <style> | |
| body { | |
| font-family: monospace; | |
| } | |
| h1 { color: pink; } | |
| </style> | |
| <h1>Hello first world!</h1> | |
| <cool-heading> | |
| <h1>Hello cool world!</h1> | |
| </cool-heading> | |
| <template> | |
| <style> | |
| h1 { color: green; } | |
| </style> | |
| <h1>Hello again!</h1> | |
| </template> | |
| <script> | |
| // your code will go here | |
| class CoolHeading extends HTMLElement { | |
| constructor() { | |
| super(); | |
| this.addEventListener('click', () => { | |
| this.style.color = 'red'; | |
| }); | |
| } | |
| connectedCallback() { | |
| console.log('CoolHeading connected!'); | |
| this.style.color = 'blue'; | |
| const template = document.querySelector('template'); | |
| const clone = document.importNode(template.content, true); | |
| this.attachShadow({ mode: 'open' }); | |
| this.appendChild(clone); | |
| } | |
| } | |
| customElements.define('cool-heading', CoolHeading); | |
| <\/script> | |
| </body> | |
| </html> | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment