-
Notifications
You must be signed in to change notification settings - Fork 0
/
index5.html
38 lines (34 loc) · 1.15 KB
/
index5.html
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
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Recebendo Atributos</title>
<script>
class HelloWorldElement extends HTMLElement {
static observedAttributes = ["data-name"]
constructor() {
super()
this.attachShadow({ mode: "open" })
this.spanEl = document.createElement("span")
this.shadowRoot.append(this.spanEl)
}
connectedCallback() {
const name = this.getAttribute("data-name")
this.spanEl.textContent = `Hello, ${name}!`
}
attributeChangedCallback(attr, oldValue, newValue) {
if(attr === "data-name") {
this.spanEl.textContent = `Hello, ${newValue}!`
}
}
}
customElements.define("hello-world", HelloWorldElement)
</script>
</head>
<body>
<h1>Exemplo 05</h1>
<hello-world data-name="João"></hello-world>
</body>
</html>