Replace image with text after 5 seconds of delay

Goal
Replace one div with another after a 5 second delay using jQuery.

Description
I would like to show the image in the div for 5 seconds, after which it needs to be replaced with text in another div.

HTML code

<div id="outer">Image here</div>
<div id="text">Text here</div>

JQuery code

<script type="text/javascript">
    $(document).ready(function()
    {
        setTimeout(function()
        {
            $("div#outer").fadeOut("slow", function ()
            {
                $("div#outer").remove();
            });
         }, 5000);
     });
</script>

Thanks in advance.

+3
source share
3 answers

Here is a demo link: http://jsfiddle.net/pHJgP/8/

HTML code:

<div id="outer"><img src="http://existdissolve.com/wp-content/uploads/2010/08/microsoft-logo-64x64.png" alt="" /></div>
<div id="text" style="display:none">Text here</div>

Jquery Code:

$(document).ready(function()
    {
        setTimeout(function()
        {
            $("div#outer").fadeOut("slow", function ()
            {
                $("div#outer img").remove();                
                $("div#outer").html($("div#text").text());
                $("div#outer").show();
            });
         }, 5000);
     });

Hope this will be helpful to you.

+1
source

Try the following:

<script type="text/javascript">
        $(document).ready(function()
        {
            setTimeout(function()
            {
                $("div#outer").fadeOut("slow", function ()
                {
                    $("div#outer").hide();
                    $("div#text").show();
                });
             }, 5000);
         });
    </script>

Or, if you are actually trying to move the text contained in div textto div outer, do the following:

<script type="text/javascript">
            $(document).ready(function()
            {
                setTimeout(function()
                {
                    $("div#outer").fadeOut("slow", function ()
                    {
                        $("div#outer").html($("div#text").html()); //.html or .text
                    });
                 }, 5000);
             });
        </script>
+4
source

, , - , JavaScript .

Just place the image container above the text and disappear, as you already did:


Javascript

$(function() {
    setTimeout(function()
    {
        var $el = $('div#outer');        
        $el.fadeOut("slow", $el.remove);
     }, 5000);
});​

HTML

<div class="transition-wrapper">
    <div id="outer">Image here</div>
    <div id="text">Text here</div>
</div>

CSS

Please note that the colors here are for illustration purposes only.

.transition-wrapper {
    position: relative;    
    width: 500px;
    height: 500px;
}
#outer {
    position:absolute;
    z-index: 100;
    width: 500px;
    height: 500px;
    background: red;
}
#text {
    background: blue;
    height: 100%;
    width: 100%;
}

Jsfiddle

http://jsfiddle.net/mJUzr/

+1
source

All Articles