I'm trying a simple jQuery script to fadeout one div and fadein another one in it's place but for some reason the first div never fades out. It's probably an obvious problem with the code but I cannot seem to make it out.
<style>
#cuerpo { display: none; }
</style>
<div id="cuerpo"></div>
<div id="inicio"></div>
<script>
function delayed() {
$("div").fadeIn(3000, function () {
$("cuerpo").fadeIn("slow");
});
}
$("a").click(function () {
$("inicio").fadeOut("slow");
setTimeout("delayed()",500);
});
</script>
How should I do it? What am I doing wrong?
I'm trying a simple jQuery script to fadeout one div and fadein another one in it's place but for some reason the first div never fades out. It's probably an obvious problem with the code but I cannot seem to make it out.
<style>
#cuerpo { display: none; }
</style>
<div id="cuerpo"></div>
<div id="inicio"></div>
<script>
function delayed() {
$("div").fadeIn(3000, function () {
$("cuerpo").fadeIn("slow");
});
}
$("a").click(function () {
$("inicio").fadeOut("slow");
setTimeout("delayed()",500);
});
</script>
How should I do it? What am I doing wrong?
Share Improve this question edited Feb 23, 2017 at 14:23 dakab 5,87510 gold badges45 silver badges70 bronze badges asked Jun 30, 2011 at 6:11 lisovaccarolisovaccaro 34k99 gold badges269 silver badges423 bronze badges3 Answers
Reset to default 12UPDATE
The simplest way to do this is by using a callback:
$('a').click(function(){
$('#fadeout').fadeOut(300, function () {
$('#fadein').fadeIn(300);
});
});
then the HTML:
<a href="#">In/Out</a>
<div id="fadeout">Fade Out</div>
<div id="fadein" style="display:none;">Fade In</div>
OLD:
There is a simple way to do this:
$('a').click(function(){
$('#fadeout').fadeOut(300);
$('#fadein').delay(400).fadeIn(300);
});
I think you can use callback...
$('#fadeout').fadeOut(300, function(){
$("#fadein").fadeIn(300);
});
this is the most stable way....
There is a syntax error it should be
$("#inicio").fadeOut("slow");
and not
$("inicio").fadeOut("slow");
Similarly
$("#cuerpo").fadeIn("slow");
and not
$("cuerpo").fadeIn("slow");