class CustomCommentsSection extends HTMLElement { connectedCallback() { this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = `
Comments
Tom Anderson
2 days ago
Welcome to MySpace! This is going to be awesome!
Chris DeWolfe
1 day ago
Great profile! Check out the new features we added!
`; // Comment form submission this.shadowRoot.querySelector('.comment-form button').addEventListener('click', () => { const text = this.shadowRoot.querySelector('.comment-form textarea').value; if (text.trim()) { const comment = document.createElement('div'); comment.className = 'comment'; comment.innerHTML = `
New User
Just now
${text}
`; this.shadowRoot.querySelector('.comments-list').prepend(comment); this.shadowRoot.querySelector('.comment-form textarea').value = ''; } }); } } customElements.define('custom-comments-section', CustomCommentsSection);