AVersa
AVersa

Reputation: 25

Set delay time in javascript

I have a welcome popup on my home page site.

I have this Javascript

<script type="text/javascript">
    $(document).ready(function () {
        $("#div-welcome").dialog({
              width: 'auto',
              height: 'auto',
              modal: true
        });
    });
</script>

How can I set a delay of 3 seconds? I tried with setTime function but that didn't work. Maybe I put it in the wrong place. Thank you! AVersa

Upvotes: 2

Views: 261

Answers (2)

codingrose
codingrose

Reputation: 15699

Use setTimeout.

The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.

Write this:

$(document).ready(function () {
    setTimeout(function(){
        $("#div-welcome").dialog({
            width: 'auto',
            height: 'auto',
            modal: true
        });
    },3000);
});

Upvotes: 1

Joe Simmons
Joe Simmons

Reputation: 1848

$(document).ready(function () {
    window.setTimeout(function () {
        $("#div-welcome").dialog({
              width: 'auto',
              height: 'auto',
              modal: true
        });
    }, 3000);
});

Upvotes: 0

Related Questions