I have the below global jQuery function stored, but on page load, I want to execute it after a 1000 delay. Is there something wrong with my syntax? I know the delay always goes
This answer is just useful to understand how you can make delay using JQuery delay
function.
Imagine you have an alert and you want to set the alert text then show the alert and after a few seconds hide it.
Here is the simple solution:
$(".alert-element").html("I'm the alert text").fadeIn(500).delay(5000).fadeOut(1000);
It is completely simple:
.html()
will change the text of .alert-element
.fadeIn(500)
will fade in after 500 millisecondsdelay(5000)
function will make 5000 milliseconds of delay before calling next function.fadeOut(1000)
at the end of the statement will fade out the .alert-element