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

152
Vistas
Set global variable with callback not working - javascript

I want to use the height of the image outside the onload function. I tried this, but it's not working

                var nr;
                function getHeightOfImage(src, cb) {
                var img = document.createElement('img');
                img.onload = function () {
                    cb(this.height);
                };
                img.src = src;
            }


            getHeightOfImage(vid.Image, function (height) {
                console.log("height", height); //height available
                nr = height; // nr setted here
            });


            console.log("nr", nr); //nr - is not setted here
about 4 years ago · Juan Pablo Isaza
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