# On Click module load

**URL:** <https://community.hubspot.com/t/on-click-module-load/102889>\
**Category:** CMS Development\
**Tags:** professional, starter\
**Created:** [March 19, 2024, 12:14pm UTC](https://community.hubspot.com/t/on-click-module-load/102889 "2024-03-19T12:14:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shadow42](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/shadow42/32/49879_2.png) [@shadow42](https://community.hubspot.com/u/shadow42)\
**Post date:** [March 19, 2024, 12:14pm UTC](https://community.hubspot.com/t/on-click-module-load/102889/1 "2024-03-19T12:14:03Z")

</div>

Hi,  
When URL is hit in that case I don’t want embedded Youtube video to load simultaneously when the page loads.  
So I was thinking of creating a Module in such a way that when clicked on div then we could load the YouTube video on a pop-up or could replace the existing div with youtube embedded div.  
the main objective is not to load the embedded YouTube code when the page is loading in order to load the page faster.  
Is that possible?

---

<div class="post-metadata">

**Author:** ![evaldas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/evaldas/32/69160_2.png) [@evaldas](https://community.hubspot.com/u/evaldas)\
**Post date:** [March 19, 2024, 4:11pm UTC](https://community.hubspot.com/t/on-click-module-load/102889/2 "2024-03-19T16:11:26Z")

</div>

Hi @shadow42

Yes, that is possible. You can create a module in HubSpot that triggers a popup when an element is clicked and only then the iframe would be loaded into the popup.

Basic HTML for this that includes the trigger and the popup:

```lia-code-sample
<!-- the button is the trigger here but you can update it to be a div, as long as it has the appropriate ID -->
<button id="openModal">Open Modal</button>

<!-- the popup -->
<div id="popupModal" class="modal">
 <div class="modal-content">
 <span class="close">×</span>
 <div id="videoContainer"></div>
 </div>
</div>

```

Some basic CSS to style the popup so that it’s centered and has a close button:

```lia-code-sample
.modal {
 display: none;
 position: fixed;
 z-index: 1;
 left: 0;
 top: 0;
 width: 100%;
 height: 100%;
 background-color: rgba(0,0,0,0.5);
}

.modal-content {
 position: absolute;
 background-color: #fefefe;
 padding: 20px;
 border-radius: 10px;
 left: 50%;
 top: 50%;
 transform: translate(-50%, -50%);
}

.close {
 color: #aaa;
 float: right;
 font-size: 28px;
 font-weight: bold;
 cursor: pointer;
}

.close:hover,
.close:focus {
 color: black;
 text-decoration: none;
 cursor: pointer;
}

```

Here is the javascript to tie it all together (replace the “VIDEO\_ID\_HERE” with the actual video ID)

```lia-code-sample
document.getElementById('openModal').addEventListener('click', function() {
 let modal = document.getElementById('popupModal');
 let videoContainer = document.getElementById('videoContainer');

 videoContainer.innerHTML = '<iframe width="560" height="315" src="https://www.youtube.com/embed/VIDEO_ID_HERE" frameborder="0" allowfullscreen></iframe>';

 modal.style.display = 'block';

 document.getElementsByClassName('close')[0].addEventListener('click', function() {
 modal.style.display = 'none';
 videoContainer.innerHTML = '';
 });
});

```

Hope this helps!
