Skip to content

Commit 9f03244

Browse files
committed
Improve web component example
1 parent a927243 commit 9f03244

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

JavaScript/3-abstraction.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@
99
constructor() {
1010
super();
1111
this.attachShadow({ mode: 'open' });
12+
this.clicked = false;
1213
}
1314

1415
connectedCallback() {
15-
this.shadowRoot.innerHTML = `<h1>${this.getAttribute('name')}</h1>`;
16+
const html = `<h1>Marcus</h1><button type="button">Ave Marcus!</button>`;
17+
this.shadowRoot.innerHTML = html;
18+
this.shadowRoot.querySelector('button').addEventListener('click', () => {
19+
if (!this.clicked) {
20+
this.clicked = true;
21+
const html = `<h1>Ave Marcus Aurelius!</h1>`;
22+
this.shadowRoot.innerHTML = html;
23+
}
24+
});
1625
}
1726
}
1827

@@ -21,6 +30,6 @@
2130
</script>
2231
</head>
2332
<body>
24-
<page-caption name="Marcus">Marcus Aurelius</page-caption>
33+
<page-caption></page-caption>
2534
</body>
2635
</html>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy