We help IT Professionals succeed at work.
Get Started

Execute jQuery after Function

Elizabeth Shaules
on
332 Views
Last Modified: 2017-04-27
Hello,

I am embedding a form from HubSpot with this code:
<script>
  hbspt.forms.create({ 
    css: '',
    portalId: 'XXXXXXX',
    formId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
  });
</script>

Open in new window


On page load, this injects a DIV with a form in it.  This DIV has an identifying class "hbspt-form" (which I cannot control the name of, or adding ID's, etc.)    To style it, I am trying to execute this line of code after the above code:
jQuery('[name="firstname"]').addClass( "wpcf7-form-control wpcf7-text" );

Open in new window


Which doesn't work because its executing BEFORE the hbspt.forms.create function (as far as I can tell.)  If I run the jQuery line in the console, after all has loaded, the line works perfectly.  Can you help me create the code necessary to append those two classes at the correct time?

Thanks!
Comment
Watch Question
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE