From 501254cd4f38042cb8918808a97ac646eeec0187 Mon Sep 17 00:00:00 2001 From: Matthew Huntington Date: Sat, 8 Feb 2025 10:11:25 -0500 Subject: [PATCH] attribute on component --- component.js | 13 ++++++++++--- index.html | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/component.js b/component.js index f65d5a2..c46a003 100644 --- a/component.js +++ b/component.js @@ -1,17 +1,24 @@ -class MyComponent extends HTMLElement { +class Pet extends HTMLElement { constructor() { super(); const shadow = this.attachShadow({ mode: 'closed' }); const root = document.createElement('section'); + + const name = this.getAttribute('name') + root.innerHTML = ` -

Hello from MyComponent!

+

Pet

+
+
Name
+
${name}
+
`; shadow.appendChild(root) } } -customElements.define('my-component', MyComponent); +customElements.define('pet-component', Pet); diff --git a/index.html b/index.html index c32ad17..397ec0a 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,6 @@ - +