-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello-world.html
More file actions
39 lines (31 loc) · 1.13 KB
/
hello-world.html
File metadata and controls
39 lines (31 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<template id="hello-world">
<style>
:host {
display: block;
padding: 1em 1em;
border: 1px solid black;
}
p { color: red; }
</style>
<p>Hello <span id="name">World</span></p>
<input type="text" id="myName">
</template>
<script>
const templateHelloWorld = (document.currentScript || document._currentScript).ownerDocument.querySelector('#hello-world').content;
class HelloWorld extends HTMLElement {
connectedCallback() {
let shadowRoot = this.attachShadow({mode: 'open'});
const content = document.importNode(templateHelloWorld, true)
this.shadowRoot.appendChild(content)
shadowRoot.getElementById("myName").addEventListener("input", e => {this.nameChanged();});
}
nameChanged(){
var name = this.shadowRoot.getElementById('myName').value;
if(!name){
name = "World";
}
this.shadowRoot.getElementById('name').textContent = name;
}
};
window.customElements.define('hello-world', HelloWorld);
</script>