Good

I must say, the question is different from thousands of similar ones on the Internet.

//function 1 $(".div1").click(function(){ ...очень много кода }); 

Is it possible to call a function call every second, in JQ code?

 //function 1 $(".div1").click(function calculate(){ ...очень много кода }); //вот это, не работает. с простыми JS работает, но в JQ нет setTimeout(calculate(), 1000); 

1 answer 1

setTimeout will not execute your code "every second". It is carried out through the set number of seconds, 1 time. SetInterval should be used.

calculate() apparently you only have in the handler .click , respectively setTimeout(calculate(), 1000); It leads to nothing, it cannot see this function, it is not available for setTimeout() .

If I correctly understood the task, then you can use .trigger () . Like that:

 $(".div1").click(function calculate(){ console.log("alert"); }); setInterval(function() { $(".div1").trigger("click"); }, 2000); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="div1">1111</div> 

  • learned a lot! THX. on the problem exactly the way it happened - gforce
  • either just make calculate an ordinary function - Grundy