Harman Preet
Harman Preet

Reputation: 207

show div after 5 seconds and then refresh the div every 1 min

I have created a div into my page which i wanted to get load after 5 seconds the page get load. Then I wanted to refresh the div without refreshing the page after every 1 min. How can I achieve this functionality with the use of J query. My code look like this

$(document).ready(
    function () {
        setInterval(function() {
            $('#newsletter').show();
        }, 100000);

  });

This upper block of code is only refreshing the div after 1 min. But on page load , i want the div to be shown to the user after 5 seconds and then this block of code should executed.

Upvotes: 0

Views: 2908

Answers (4)

friedi
friedi

Reputation: 4360

Here is a jQuery solution:

$(document).ready(function () {
    var $newsletter = $('#newsletter')
        .delay(5000)
        .show(function() {
            setInterval(function() {
                // update the newsletter, e.g. set new text
                $newsletter.text(new Date());
            }, 60000);
        });
});

Upvotes: 0

XtraSimplicity
XtraSimplicity

Reputation: 6052

You've already got the base functionality there, so all you'll need to do is add a message to appear after 5 seconds. Something like this should work.

$(document).ready(function()
 {
   setTimeout(function() { 
          // show message
      },5000);

     setInterval(function() {
        $('#newsletter').show();
    }, 60000);
  });

Upvotes: 0

Apul Gupta
Apul Gupta

Reputation: 3034

Try it:

$(function(){
 setTimeout(function(){
$('#newsletter').show(); // to show div after 5 sec of page load

// To reshow on every one minute
setInterval(function() {
            $('#newsletter').show();
        }, 60000);
  }, 5000);

});

Upvotes: 0

Luke
Luke

Reputation: 4063

$(document).ready(function()
{
    setTimeout(function()
    {
        // Perform actions you need to
        setInterval(function()
        {
            // Perform them again every minute
        }, 60000);

    }, 5000);
});

I think what you were looking for is setTimeout

Upvotes: 0

Related Questions