Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!