How to call a jquery function onload with some delay?
I want to call a function like this on load with some delay
$(\".sample\").live(\'click\',function(
you could use setTimeout function you must refactor your code as something like this
//2 seconds wait before calling doJob
$(".sample").live('click',function(){ setTimeout(doJob, 2000);});
function doJob(){
var id=$(this).attr("id");
//other statements ...
}
This will wait 1 second and then assign the event handler...
function assignSampleClick() {
$(".sample").live('click',function(){
var id=$(this).attr("id");
});
}
// document ready
$(function() {
setTimeout(assignSampleClick, 1000);
});
Try it like this..
$(document).ready(function () {
setTimeout(function () {
$(".sample").live('click',function(){
var id=$(this).attr("id");
}, 3000);
}, 3000);
This will fire on page load after 3 seconds delay.
Try to use Timer Plugin
$(this).oneTime(1000, function() {
// some action here
});
try this
var demora = window.setInterval(lerolero, 3000);
function lerolero() {
$("#ovo").css("display", "block");
}