@@ -44,7 +44,10 @@ class StopWatchElement extends HTMLElement {
44
44
shadowRoot = this .attachShadow ({ mode: " open" })
45
45
46
46
connectedCallback () {
47
- this .shadowRoot .innerHTML = ` <p >Hello World!</p >`
47
+ this .shadowRoot .innerHTML = `
48
+ <span >00:00:00</span >
49
+ <button >Start</button >
50
+ `
48
51
}
49
52
}
50
53
```
@@ -61,7 +64,10 @@ complexity.
61
64
``` js
62
65
// The template can be defined up front and re-used
63
66
const template = document .createElement (" template" )
64
- template .innerHTML = ` <p >Hello World!</p >`
67
+ template .innerHTML = `
68
+ <span >00:00:00</span >
69
+ <button >Start</button >
70
+ `
65
71
66
72
class StopWatchElement extends HTMLElement {
67
73
static define (tag = " stop-watch" ) {
@@ -87,7 +93,8 @@ handle attaching a _shadow root_ and cloning the contents of the template for yo
87
93
``` html
88
94
<stop-watch >
89
95
<template shadowrootmode =" open" >
90
- <p >Hello World</p >
96
+ <span >00:00:00</span >
97
+ <button >Start</button >
91
98
</template >
92
99
</stop-watch >
93
100
```
@@ -101,8 +108,8 @@ class StopWatchElement extends HTMLElement {
101
108
connectedCallback () {
102
109
// The component's ShadowDOM is now available as
103
110
// this.shadowRoot:
104
- const pEl = this .shadowRoot .querySelector (" p " )
105
- console .assert (pEl .outerHTML === " <p>Hello world</p> " )
111
+ const el = this .shadowRoot .querySelector (" span " )
112
+ console .assert (el .outerHTML === ` <span>00:00:00</span> ` )
106
113
}
107
114
}
108
115
```
@@ -123,7 +130,10 @@ JavaScript instead. You can do this by checking if `.shadowRoot` is not null bef
123
130
124
131
``` js
125
132
const template = document .createElement (" template" )
126
- template .innerHTML = ` <p >Hello World!</p >`
133
+ template .innerHTML = `
134
+ <span >00:00:00</span >
135
+ <button >Start</button >
136
+ `
127
137
128
138
class StopWatchElement extends HTMLElement {
129
139
static define (tag = " stop-watch" ) {
@@ -191,7 +201,8 @@ one can also get the _closed ShadowRoot_:
191
201
``` html
192
202
<stop-watch >
193
203
<template shadowrootmode =" closed" >
194
- <p >Hello World</p >
204
+ <span >00:00:00</span >
205
+ <button >Start</button >
195
206
</template >
196
207
</stop-watch >
197
208
```
0 commit comments