Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace image with text after 5 seconds delay

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

Description
I would like to show an image in a div for 5 seconds and after that it should 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.

like image 455
kexxcream Avatar asked May 03 '26 09:05

kexxcream


2 Answers

Try this:

<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're actually trying to move the text contained in div text into div outer, do this:

<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>
like image 145
Norse Avatar answered May 04 '26 23:05

Norse


Here is the 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 is helpful for you.

like image 21
Rony SP Avatar answered May 05 '26 01:05

Rony SP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!