Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defined example fix #78

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions defined-pseudo-class/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,33 @@
<head>
<meta charset="utf-8">
<title>:defined demo</title>
<script src="main.js" defer></script>
<script src="main.js"></script>
<style>
p {
background: yellow;
}

simple-custom {
background: cyan;
}

:defined {
font-style: italic;
}

simple-custom:not(:defined) {
display: none;
simple-custom {
text-transform: uppercase;
background: cyan;
}

simple-custom:defined {
display: block;
simple-custom:not(:defined) {
display: none;
}
</style>
</head>
<body>
<h1><code>:defined</code> demo</h1>

<simple-custom text="Custom element example text"></simple-custom>
<p>The <code>&lt;simple-custom&gt;</code> element type is <simple-custom>NOT</simple-custom> undefined.</p>

<p>Standard paragraph example text</p>
<p>Click the button below to make <code>&lt;simple-custom&gt;</code> a custom element.</p>

<button id="button1" onclick="defineSimpleCustom()">Define <code>&lt;simple-custom&gt;</code></button>
</body>
</html>
</html>
21 changes: 9 additions & 12 deletions defined-pseudo-class/main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
customElements.define('simple-custom',
class extends HTMLElement {
constructor() {
super();

const divElem = document.createElement('div');
divElem.textContent = this.getAttribute('text');

const shadowRoot = this.attachShadow({mode: 'open'});
shadowRoot.appendChild(divElem);
function defineSimpleCustom() {
customElements.define("simple-custom",
class extends HTMLElement {
constructor() {
super();
}
}
}
);
);
document.getElementById("button1").remove();
}
Loading