HubSpot Custom CTA Close Button Not Working? Here's the Community-Backed Fix!

HubSpot Custom CTA Close Button Not Working? Here's the Community-Backed Fix!

Ever poured your heart into designing a sleek, custom HTML banner in HubSpot, only to find its essential close button utterly unresponsive? You’re not alone. It’s a classic head-scratcher that recently popped up in the HubSpot Community, and the solution offers a fantastic peek into how to truly leverage HubSpot’s power – even when it tries to be a bit too 'helpful'.

At ESHOPMAN, we’re all about making HubSpot the best website platform for online store operations, and that often means getting creative with its built-in features. This particular community discussion perfectly illustrates a common challenge when you're building your own ecommerce platform experience within HubSpot's framework.

The Mystery of the Unclickable Close Button

The original poster in the community thread was trying to implement a floating banner using HubSpot’s custom HTML via the CTA feature. The banner looked great, but the close button? Useless. When clicked, it would simply redirect to the banner’s main link, refusing to dismiss the banner itself.

The culprit, as expertly identified by a community member, is HubSpot’s internal mechanism for tracking. When you create a custom HTML/interactive CTA, HubSpot’s engine automatically wraps your entire HTML block in an anchor tag (). This wrapper sits 'higher' in the Document Object Model (DOM) hierarchy, meaning it intercepts all clicks before they can ever reach your carefully crafted internal button.

Think of it like this: you’ve put a tiny, specific doorbell on your house (your close button), but someone else has put a giant, invisible blanket over your entire house (HubSpot’s wrapper link). When you try to press the doorbell, you just end up pressing the blanket, which then takes you somewhere else entirely.

The Ingenious JavaScript & CSS Workaround

Thankfully, the HubSpot community is a treasure trove of clever solutions. One helpful respondent provided a robust fix involving a bit of JavaScript event control and some strategic CSS. The core idea is to tell the browser, 'Hey, when this specific button is clicked, stop the click event right here – don't let it travel up to the parent wrapper!'

The Solution: stopPropagation() and preventDefault()

These two JavaScript commands are your best friends here:

  • event.preventDefault();: This stops the browser’s default action for the element (in this case, preventing the link from opening).
  • event.stopPropagation();: This is the real hero. It prevents the click event from 'bubbling up' to parent elements, effectively stopping HubSpot’s wrapper link from ever knowing the button was clicked.

Step-by-Step Implementation

1. Update Your HTML in the CTA Editor

Locate your close button’s HTML within the CTA editor and modify it to include the onclick attribute with our special JavaScript commands. Here’s how the updated button tag should look:

banner

Notice the document.getElementById('floatingBanner').style.display='none'; part? That’s what actually hides your banner when the button is clicked!

2. Add Essential CSS (Styles Tab)

To ensure your close button is not just logically but also physically clickable and visually on top, you need to give it a high z-index and explicitly tell the browser it accepts clicks using pointer-events: auto;.

.close-btn {
 position: absolute;
 top: 10px;
 right: 10px;
 z-index: 9999; /* Ensures it sits above the HubSpot link layer */
 cursor: pointer;
 pointer-events: auto; /* Explicitly tells the browser this element accepts clicks */
}

Why This Works: Understanding Event Bubbling

In web development, when an event (like a click) occurs on an element, it first triggers on that element, then 'bubbles up' through its parent elements all the way to the document root. By using event.stopPropagation(), you’re essentially erecting a barrier. The browser executes your 'hide banner' command, but the click event never reaches HubSpot’s wrapper tag, thus preventing the unwanted redirect.

How to Verify Your Fix

Once implemented, perform these quick tests:

  • The Hover Test: Hover over the main banner image; you should see the destination URL in your browser's status bar. Now, hover over the '×' close button. That URL should disappear, or your cursor should clearly indicate it's a pointer, not a link.
  • The Click Test: Click the '×'. If the banner vanishes and you stay on the same page, congratulations – your logic is working perfectly!

Pro-Tip for HubSpot CTAs

A community member also shared a useful tip: if you find event.stopPropagation() is still being overridden (which can happen with complex HubSpot internal scripts), double-check the Advanced section of your CTA. Ensure your 'close' element is a