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

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

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

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 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