---
title: "Discussion on \"How To Create Reusable HTML Components Using Only JavaScript\" | Hashnode"
description: "Discussion on \"How To Create Reusable HTML Components Using Only JavaScript\". A modern way of creating Single Page Applications without any frontend framework"
url: "https://hashnode.com/posts/create-reusable-html-components-with-javascript/64c2ddc261b710e7e3bb8ec2"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How To Create Reusable HTML Components Using Only JavaScript](https://saje.hashnode.dev/create-reusable-html-components-with-javascript?utm_source=hashnode&utm_medium=feed)

A modern way of creating Single Page Applications without any frontend framework

Jul 27, 2023 · 12 min read · saje.hashnode.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#html5](https://hashnode.com/tag/html5)
-   [#web-development](https://hashnode.com/tag/web-development)
-   [#web-components](https://hashnode.com/tag/web-components)

## Written by

[Paul Saje](https://hashnode.com/@Saje)

@Saje · Nigeria

  
[View profile](https://hashnode.com/@Saje)

React/JS developer

I'm a front-end React/JS developer. I share tips and tricks I learn every day on my journey to becoming a better developer.

## Responses 1

Markdown supported · ⌘↵ to post

[William Owen](https://hashnode.com/@williamowendev)

[Oct 17, 2024](https://hashnode.com/posts/create-reusable-html-components-with-javascript/64c2ddc261b710e7e3bb8ec2/comment/6711a0ca83b2ac1440eea0bd)

You mentioned a way to assign an event to a button within a slot, and mentioned how the event doesn't get added to slot content that is injected... Using delegated event handling, you can get around that. The basic idea is that the click event is on the shadow dom, and in the event handler we check if the button was clicked.

connectedCallback() { this.shadowRoot.addEventListener('click', (e) => { if(e.target.closest('.primary-btn')){ console.log('shadow event triggered!') } }) }
