Reputation: 1011
I want to show an element and hide an element at the same time, 2 seconds after the page has loaded, I know the below code is not right, but I am just using it to help understand the logic I am trying to achieve.
delay(2000).$('#customer_contact').hide().$('#customer_contact_edit_cont').show();
How could this logic best be written?
Upvotes: 0
Views: 29
Reputation: 475
You should use the setTimeout
function.
setTimeout(
function(){
//Do something
}, 5000);
Here 5000
being the time in milliseconds. (1 sec = 1000 ms
)
Upvotes: 0
Reputation: 337560
Aside from the syntax issues, the delay()
function is intended to delay animations from happening which are scheduled to run on jQuery's fx
queue.
If you want to delay an action from occurring outside of animation then you can use setTimeout()
, like this:
setTimeout(function() {
$('#customer_contact').hide();
$('#customer_contact_edit_cont').show();
}, 2000);
Upvotes: 1