Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda