Grab the RSS feed

Set Interval and Set timeout difference in Jquery

Set timeout in Jquery call the function only once.But the Set interval call the function again and again for the time limit we are given.
But if you want to make the websites such as update the user status and other things you are advice to use set time interval.

If you want to call a function after particular seconds(Such as delay) use the set time out function.

< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > 
< html xmlns="http://www.w3.org/1999/xhtml" > 
< head > 
< script type="text/javascript" src="jquery/jquery-1.3.2.min.js" > < /script > 
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" / > 
< title > setTimeout/setInterval< /title > 
< script > 
$(document).ready(function(){
$("#settimeoutfunc").click(function()
{
alert('clciked,Please wait 20 seconds');
setTimeout('alert(\'Settimeout is cliked\')',20000);
});
$("#setIntervalfunc").click(function()
{
alert('clciked,Please wait 20 seconds');
setInterval('alert(\'SetInterval is cliked\')',20000);
});
//alert('test');
});
< /script > 
< /head > 
< body > 
< input type="button" value="settimeout" onclick="" id="settimeoutfunc"/ > 
< input type="button" value="setInterval" onclick="" id="setIntervalfunc"/ > 
< /body > 
< /html > 

0 comments:

  •  
    Real Time Web Analytics