El título lo dice todo, he seguido todos los tutoriales que pude encontrar, pero mi alerta () nunca se ejecuta. No tengo idea de lo que estoy haciendo mal.
var right = document.getElementById("right-container"); right.animate({ backgroundColor: '#fff' }, { duration: 550, complete: function () { alert('hello') } });`Aquí hay un violín simple para mostrar el problema al que me enfrento: https://jsfiddle.net/5shwn8r1/
Está seleccionando un elemento dom, no un elemento jquery, envuelva su elemento dom con $()
var right = document.getElementById("right-container"); $(right).animate({ backgroundColor: '#fff' }, { duration: 550, complete: function () { alert('hello') } }); O puede seleccionarlo con jQuery directamente: $('#right-container')
Para animar las propiedades background-color , también incluí un complemento de jQuery en <head /> :
<script src="//cdn.jsdelivr.net/jquery.color-animation/1/mainfile"></script>violín: https://jsfiddle.net/74c8xu1k/
Deberías probar este código:
<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>A mí me funciona y la alerta se muestra cuando hago clic en el texto 'haz clic en mí'.