Reputation: 3
i want to call a javascript function from a div every seconds. and i also pass arguments with this function
function myFunc(a) {
alert(a);
setInterval("myFunc(a)", 1000);
}
myFunc(a);
<div myFunc(5)></div>
Upvotes: 0
Views: 482
Reputation: 352
JavaScript Window setInterval() Method see
<button onclick="myFunction('param')">Try it</button>
<script>
function myFunction(a) {
setInterval(function(){ alert(a); }, 1000);
}
</script>
Upvotes: 1
Reputation: 5473
Try below code where page will be auto refreshed after 1min and that time on page load you are calling your function
var refresh_mili_sec=60000; //60000=1min
$(document).ready(function(){
var a=5;
myFunc(a);
setTimeout(function()
{
window.location.reload(1);
}, refresh_mili_sec);
});
function myFunc(a) {
alert(a);
}
Upvotes: 0