Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda