Skip to content

Instantly share code, notes, and snippets.

@rudifa
Created March 29, 2020 15:12
Show Gist options
  • Select an option

  • Save rudifa/32c9fd5b3f9bc5807bbdf37bcfa77a7d to your computer and use it in GitHub Desktop.

Select an option

Save rudifa/32c9fd5b3f9bc5807bbdf37bcfa77a7d to your computer and use it in GitHub Desktop.
<!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