Manipulating HubSpot CTAs via JavaScript

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?

Hey @db_509

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?

Hey @db_509 - 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 to ensure the entire DOM (include the CTA button) has loaded.

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