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

144
Vistas
JQuery animate complete function doesn't run

Title says it all really, I've followed every tutorial I could find but my alert() never gets run. I have no idea what I'm doing wrong.

    var right = document.getElementById("right-container");
    right.animate({
        backgroundColor: '#fff'
    }, {
        duration: 550,
        complete: function () {
            alert('hello')
        }
    });`

Here's a simple fiddle to show the issue I am facing: https://jsfiddle.net/5shwn8r1/

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You are selecting a dom element, not jquery element, wrap your dom element with $()

    var right = document.getElementById("right-container");
    $(right).animate({
        backgroundColor: '#fff'
    }, {
        duration: 550,
        complete: function () {
            alert('hello')
        }
    });

Or you can select it with jQuery directly : $('#right-container')

To animate the background-color properties, I also included a jQuery plugin in the <head />:

<script src="//cdn.jsdelivr.net/jquery.color-animation/1/mainfile"></script>

Read more

fiddle: https://jsfiddle.net/74c8xu1k/

about 4 years ago · Juan Pablo Isaza Denunciar

0

You should try this code :

<div id="right-container" class="container-right">
   <a onclick="switchPage(this)">click me</a>
</div>

<script>
    function switchPage(e) {
        var right = document.getElementById("right-container");
        jQuery(right).animate({
            backgroundColor: '#fff'
        }, 550, function () {
                alert('hello');
        });
    }
</script>

It's working for me and the alert is showing when i clicked on the 'click me' text.

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