# js trigger CTA btn

**URL:** <https://community.hubspot.com/t/js-trigger-cta-btn/102544>\
**Category:** Lead Capture Tools\
**Tags:** ctas\
**Created:** [March 14, 2024, 8:26am UTC](https://community.hubspot.com/t/js-trigger-cta-btn/102544 "2024-03-14T08:26:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xLiu7](https://avatars.discourse-cdn.com/v4/letter/x/f19dbf/32.png) [@xLiu7](https://community.hubspot.com/u/xLiu7)\
**Post date:** [March 14, 2024, 8:26am UTC](https://community.hubspot.com/t/js-trigger-cta-btn/102544/1 "2024-03-14T08:26:15Z")

</div>

Hello!

I want to implement: when the url has a specific parameter, such as “? from=google”, the CTA form will automatically pop up when the page is opened. I tried using the js native method to trigger the button, but it didn’t work.

code:

```lia-code-sample
window.onload = function() { 
 var hasFromParam = window.location.href.includes('from'); 

 if (hasFromParam) { 

 setTimeout(function() { 

 var btn = document.querySelector('.hs-cta-trigger-button-XXXXXX'); 
 if (btn) { 
 btn.click(); 
 } else { 
 console.error('no XXXX btn'); 
 } 
 }, 3000); 
 } 
};

```

---

<div class="post-metadata">

**Author:** ![GRajput](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/grajput/32/102020_2.png) [@GRajput](https://community.hubspot.com/u/GRajput)\
**Post date:** [March 14, 2024, 12:06pm UTC](https://community.hubspot.com/t/js-trigger-cta-btn/102544/2 "2024-03-14T12:06:47Z")

</div>

Hi @xLiu7

Could you please clarify the meaning of the term “pop-up” in the context it was used? Like do you want to disable the button or open a pop-up form on click?

Thanks!

---

<div class="post-metadata">

**Author:** ![xLiu7](https://avatars.discourse-cdn.com/v4/letter/x/f19dbf/32.png) [@xLiu7](https://community.hubspot.com/u/xLiu7)\
**Post date:** [March 14, 2024, 3:05pm UTC](https://community.hubspot.com/t/js-trigger-cta-btn/102544/3 "2024-03-14T15:05:28Z")

</div>

Thanks for the reply! Pop up means that open the pop-up form as you open the page. CTA is added to the page, and when clicked the button using the class of hs-btn directly, the form opens. But when I tried using JS and jQuery trigger buttons, it actually clicked the button, but the form didn’t open.

---

<div class="post-metadata">

**Author:** ![GRajput](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/grajput/32/102020_2.png) [@GRajput](https://community.hubspot.com/u/GRajput)\
**Post date:** [March 15, 2024, 11:39am UTC](https://community.hubspot.com/t/js-trigger-cta-btn/102544/4 "2024-03-15T11:39:10Z")

</div>

Hi @xLiu7

You can’t trigger an event by a different event. You can use js to change the visibility of the popup form if the page URL has your slug. Create a function that checks URL slug if that URL has your desired slug then it should change the popup form CSS to display: the block

I hope this will help you out. Please mark it as **Solution Accepted and upvote** to help another Community member.  
Thanks!

---

<div class="post-metadata">

**Author:** ![xLiu7](https://avatars.discourse-cdn.com/v4/letter/x/f19dbf/32.png) [@xLiu7](https://community.hubspot.com/u/xLiu7)\
**Post date:** [March 18, 2024, 1:28am UTC](https://community.hubspot.com/t/js-trigger-cta-btn/102544/5 "2024-03-18T01:28:31Z")

</div>

open “Trigger after elapsed time” and set time & query parameters.
