html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html>
<html>
<head>
<title>Custom Component using HTMLElement</title>
</head>
<body>
<p>This will print: <print-once>Hello World!</print-once></p>
<p>This will not print: <print-once>Hello World!</print-once></p>
<p>This will not print: <print-once>Hello World!</print-once></p>
<p>This will not print: <print-once>Hello World!</print-once></p>
<p>This will not print: <print-once>Hello World!</print-once></p>
<p>This will not print: <print-once>Hello again!</print-once></p>
<p>This will not print: <print-once>Hello again!</print-once></p>
<p>This will not print: <print-once>Hello again!</print-once></p>
<p>This will not print: <print-once>Hello again!</print-once></p>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class PrintComponent extends HTMLElement {
static flag = false;
connectedCallback() {
PrintComponent.flag?this.innerHTML="":null;
PrintComponent.flag = true;
}
}
window.onload = load;
function load() {
window.customElements.define('print-once', PrintComponent);
}
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run