I am trying to run a function at setInterval()
of "1 second", but it is a bit problematic. I have done everything as shown here but it doesn't work.
Here is my code :
<script>
function test(db_time)
{
var c_db_time= db_time/1000;
var current_time = new Date().getTime()/1000;
return Math.round(current_time - c_db_time);
}
$(".elapsed_time").each(function() {
var time_r = $(this).data('time_raw');
var inter = $(this).html(time_ago(time_r));//parameter to function
setInterval(inter,1000)
});
</script>
And the error is :Uncaught SyntaxError: Unexpected identifier
Solution found thanks to @Bommox & @Satpal
$(".elapsed_time").each(function() {
var time_r = $(this).data('time_raw');
var self = $(this);
var inter = function() {self.html(time_ago(time_r));}
setInterval(inter, 1000);
});