attribute on component

main
Matthew Huntington 11 months ago
parent eb7b786bdd
commit 501254cd4f

@ -1,17 +1,24 @@
class MyComponent extends HTMLElement { class Pet extends HTMLElement {
constructor() { constructor() {
super(); super();
const shadow = this.attachShadow({ mode: 'closed' }); const shadow = this.attachShadow({ mode: 'closed' });
const root = document.createElement('section'); const root = document.createElement('section');
const name = this.getAttribute('name')
root.innerHTML = ` root.innerHTML = `
<h2>Hello from MyComponent!</h2> <h2>Pet</h2>
<dl>
<dt>Name</dt>
<dd>${name}</dd>
</dl>
`; `;
shadow.appendChild(root) shadow.appendChild(root)
} }
} }
customElements.define('my-component', MyComponent); customElements.define('pet-component', Pet);

@ -6,6 +6,6 @@
<script defer src="component.js"></script> <script defer src="component.js"></script>
</head> </head>
<body> <body>
<my-component></my-component> <pet-component name="fido"></pet-component>
</body> </body>
</html> </html>

Loading…
Cancel
Save