Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
Function in .then() not getting called

I am using a Promise in a function to ensure the dynamic element loaded by the function is available when I try to fix some CSS styles. But fixStyling is never executed. What am I doing wrong? Is there a better way to accomplish this?

const fixStyling = function(){
   console.log('change style');
   let surveyBody = document.querySelector('.survey-page-body');
   surveyBody.style.marginTop = "-60px";
}


function loadSM() {
    return new Promise(function(resolve) {
       (function(t,e,s,n){var o,a,c;t.SMCX=t.SMCX||[],e.getElementById(n)||(o=e.getElementsByTagName(s),a=o[o.length-1],c=e.createElement(s),c.type="text/javascript",c.async=!0,c.id=n,c.src="https://widget.surveymonkey.com/collect/website/js/tRaiETqnLgj758hTBazgd1CDe7_2F_2F4snTovolmrpjpv7u54RGrphPxAqunQp3_2FUPz.js",a.parentNode.insertBefore(c,a))})(window,document,"script","smcx-sdk");
   });
}

loadSM().then(fixStyling());

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Like Invizi mentioned,
the function takes a callback.

So either like this - loadSM().then(fixStyling);
Or like this - loadSM().then(() => fixStyling());

about 4 years ago · Juan Pablo Isaza Report

0

The reason why your code wasnt working was because of the promise you made in loadSM(). You never resolved or rejected the promise, so next was never triggered.

function fixStyling() {
  console.log('change style');
  let surveyBody = document.querySelector('.survey-page-body');
  surveyBody.style.marginTop = "-60px";
}


function loadSM() {
  return Promise.resolve(
    (function(t, e, s, n) {
      var o, a, c;
      t.SMCX = t.SMCX || [], e.getElementById(n) || (o = e.getElementsByTagName(s), a = o[o.length - 1], c = e.createElement(s), c.type = "text/javascript", c.async = !0, c.id = n, c.src = "https://widget.surveymonkey.com/collect/website/js/tRaiETqnLgj758hTBazgd1CDe7_2F_2F4snTovolmrpjpv7u54RGrphPxAqunQp3_2FUPz.js", a.parentNode.insertBefore(c, a))
    })(window, document, "script", "smcx-sdk"));
}

loadSM().then(fixStyling);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!