-1

I want to pass a variable in a function inside setInterval, i'm tried with this code but doesn't work.

Anyway function orologio(arg) append in a div a variable returned by other function orario_sisma where the second argument (formato_orologio) is passed in function orologio.

With clickevent i must to stop the first setInterval and run it another time but with new argument.

How can i do this?

   var orologio_real= setInterval(orologio(1), 1000);



   $('#A').on('click', function(){
     clearInterval(orologio_real);  

     orologio_real= setInterval(orologio(0), 1000);
   });




 function orologio (formato_orologio){
    $('#remove').remove();
    var milliseconds= new Date();
        milliseconds= milliseconds.getTime();

    var real_time= orario_sisma(milliseconds, formato_orologio);
        real_time= '<div id="remove">'+real_time+'</div>';

    $(real_time).appendTo('#data-real-time');   
}

Thanks a lot and sorry for my english.

Borja
  • 3,359
  • 7
  • 33
  • 66

1 Answers1

0

you can try like this but it is a bad practice of coding

code

var orologio_real= setInterval(orologio, 1000,1);

   $('#A').on('click', function(){
     clearInterval(orologio_real);  

     orologio_real= setInterval(orologio, 1000, 0);
   });
jasinth premkumar
  • 1,430
  • 1
  • 12
  • 22