I’m trying to dynamically insert a booking widget into my page using innerHTML when a user clicks a button, but the script part isn’t executing properly.
My current approach:
const widgetHTML = `
<div class="booking-widget-container" data-booking-url="https://example-booking.com/user123/meeting" style="min-width:300px;height:600px;"></div>
<script type="text/javascript" src="https://example-booking.com/js/embed.js" async></script>
`;
function displayBookingWidget() {
document.getElementById("widget-container").innerHTML = widgetHTML;
}
When I test this by putting regular text content between the div tags instead of the script, the text shows up fine. This tells me the DOM manipulation itself is working correctly. However, when I include the script tag for the booking widget, nothing appears on the page.
What could be preventing the script from loading when inserted via innerHTML?