@@ -44,7 +44,10 @@ class StopWatchElement extends HTMLElement {
4444 shadowRoot = this .attachShadow ({ mode: " open" })
4545
4646 connectedCallback () {
47- this .shadowRoot .innerHTML = ` <p >Hello World!</p >`
47+ this .shadowRoot .innerHTML = `
48+ <span >00:00:00</span >
49+ <button >Start</button >
50+ `
4851 }
4952}
5053```
@@ -61,7 +64,10 @@ complexity.
6164``` js
6265// The template can be defined up front and re-used
6366const 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+ `
6571
6672class StopWatchElement extends HTMLElement {
6773 static define (tag = " stop-watch" ) {
@@ -87,7 +93,8 @@ handle attaching a _shadow root_ and cloning the contents of the template for yo
8793``` html
8894<stop-watch >
8995 <template shadowrootmode =" open" >
90- <p >Hello World</p >
96+ <span >00:00:00</span >
97+ <button >Start</button >
9198 </template >
9299</stop-watch >
93100```
@@ -101,8 +108,8 @@ class StopWatchElement extends HTMLElement {
101108 connectedCallback () {
102109 // The component's ShadowDOM is now available as
103110 // 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> ` )
106113 }
107114}
108115```
@@ -123,7 +130,10 @@ JavaScript instead. You can do this by checking if `.shadowRoot` is not null bef
123130
124131``` js
125132const 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+ `
127137
128138class StopWatchElement extends HTMLElement {
129139 static define (tag = " stop-watch" ) {
@@ -191,7 +201,8 @@ one can also get the _closed ShadowRoot_:
191201``` html
192202<stop-watch >
193203 <template shadowrootmode =" closed" >
194- <p >Hello World</p >
204+ <span >00:00:00</span >
205+ <button >Start</button >
195206 </template >
196207</stop-watch >
197208```
0 commit comments