# Manipulating HubSpot CTAs via JavaScript

**URL:** <https://community.hubspot.com/t/manipulating-hubspot-ctas-via-javascript/17683>\
**Category:** CMS Development\
**Tags:** javascript\
**Created:** [December 12, 2019, 2:50pm UTC](https://community.hubspot.com/t/manipulating-hubspot-ctas-via-javascript/17683 "2019-12-12T14:50:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![db\_509](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/db_509/32/95715_2.png) [@db\_509](https://community.hubspot.com/u/db_509)\
**Post date:** [December 12, 2019, 2:50pm UTC](https://community.hubspot.com/t/manipulating-hubspot-ctas-via-javascript/17683/1 "2019-12-12T14:50:29Z")

</div>

Hello, to anyone reading. I need some suggestions ASAP

I am trying to manipulate the html code of a HubSpot CTA by adding a custom HTML attr. I’ve used the .attr() and .setAttribute() methods respectively and called the css class of the HubSpot CTA. However, it did not affect the html element. Has anyone encountered this before?

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [December 12, 2019, 9:01pm UTC](https://community.hubspot.com/t/manipulating-hubspot-ctas-via-javascript/17683/2 "2019-12-12T21:01:25Z")

</div>

Hey [@db\_509](https://community.hubspot.com/t5/user/viewprofilepage/user-id/106396)

Interesting problem.

What code have you tested with?

Have you got a live test URL that we can take a look at?

Are you getting any console errors?

---

<div class="post-metadata">

**Author:** ![daveroma](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/daveroma/32/82727_2.png) [@daveroma](https://community.hubspot.com/u/daveroma)\
**Post date:** [December 17, 2019, 3:59pm UTC](https://community.hubspot.com/t/manipulating-hubspot-ctas-via-javascript/17683/3 "2019-12-17T15:59:27Z")

</div>

Hey [@db\_509](https://community.hubspot.com/t5/user/viewprofilepage/user-id/106396) - I would need more info to get you an accurate reply but my gut is telling me the jQuery is firing before the CTA button has arrived in the DOM. If you’re running the code inside a module scope, try running it outside of the module scope, perhaps in your main.js or at the end of the page before the closing \</body\> tag - and be sure to include the jQuery selector inside a [document.ready](https://learn.jquery.com/using-jquery-core/document-ready/) to ensure the entire DOM (include the CTA button) has loaded.

```auto
$(function() {
 $('.cta_button').attr('custom-attr','cool');
});

```
