Skip to content

Instantly share code, notes, and snippets.

@kmmbvnr
Last active September 19, 2018 10:02
Show Gist options
  • Save kmmbvnr/25ac3487b16ce07df82b1eaab0e1bbf2 to your computer and use it in GitHub Desktop.
Save kmmbvnr/25ac3487b16ce07df82b1eaab0e1bbf2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript">
class MyElement extends HTMLElement {
connectedCallback() {
alert(this.children.length);
}
}
window.customElements.define('my-element', MyElement);
</script>
</head>
<body>
<my-element><p>test</p></my-element>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript">
class MyElement extends HTMLElement {
constructor() {
super(); // always call super() first in the constructor.
}
connectedCallback() {
alert(this.children.length);
}
}
window.onload = function() {
window.customElements.define('my-element', MyElement);
};
</script>
</head>
<body>
<my-element><p>test</p></my-element>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment