2

I tried the following codes (with my own functionality)

(function (){ 
  $(".video-front").show(); 
  setTimeout(arguments.callee, 10000); 
})(); 

form this post Calling a function every 60 seconds

and

setInterval(function(){ 
  $(".video-AdClick-front").show(); 
}, 10000);

from this post What's the easiest way to call a function every 5 seconds in jQuery?

but still is not working, example i want to call function every 5 sec, when i add those codes that call function only one time after 5 sec do not call function every 5 sec?

Scott Marcus
  • 64,069
  • 6
  • 49
  • 71
Lani
  • 73
  • 8
  • Please include the actual code you're using that is not working. – Heretic Monkey May 30 '18 at 22:26
  • Your code works fine. Can you clarify what you mean by it isn't working? – Kevin B May 30 '18 at 22:26
  • yes the code is corect, in my script is not working, my question is what a problem may be, who performs the function only once? – Lani May 30 '18 at 22:35
  • *"Yes, this code works, but I have a different code that doesn't work. Why does MY other code not work?"* @Luan, Seriously? If you want us to tell you why your code doesn't work, you need to post the code that doesn't work; not the one that works. – Thomas May 30 '18 at 22:46
  • honestly I do not know, but i know the code from Mr. Scott Marcus is working, but i don't say those codes are not corect i say those codes are not working with me and i don't know why, but now im happy i have fix that problem. Thank you all, Respect. – Lani May 30 '18 at 22:52

1 Answers1

2

Your timers will work just fine with either of those examples.

But, based on your comment below, it appears that both of your timer functions call the .show() method, which makes them visible. When the next timer runs, it will just show what's already being shown. That's why it appears to you that it's not working. It is working, but there's nothing new to see after the functions run the first time. What are you trying to accomplish? A show/hide situation? If that is the case, don't use .show(), use .toggle().

(function (){
    $("#one").toggle("slow");
    setTimeout(arguments.callee, 1000);
})();

setInterval(function(){
    $("#two").toggle("slow");
}, 1000);
#one, #two { float:left; width:40%; } /* Just for fun! */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="one">Message one</div>
<div id="two">Message two</div>
Scott Marcus
  • 64,069
  • 6
  • 49
  • 71
  • Thanks for your help I have add this code like this `(function (){ $(".video-front").show(); setTimeout(arguments.callee, 10000); })();` `setInterval(function(){ $(".video-AdClick-front").show(); }, 10000);` but still is not working is it shows only one time, your code is corect, i don't understand what the problem – Lani May 30 '18 at 22:31
  • @Luan As you can see, the timers work just fine. If you are experiencing a problem it must be with the code *inside* your timer callback functions. You need to post that code and all code relevant to it. – Scott Marcus May 30 '18 at 22:34
  • Yes This is Working :) Thanks for your help. – Lani May 30 '18 at 22:44
  • @Luan Please edit your question to include the code you added in the comment, as I asked you to do in my comment to your question. – Heretic Monkey May 30 '18 at 22:48
  • Mr.Scott Marcus Have edit it now so my probelm is solved, but Thanks for your help MR.@MikeMcCaughan Really Thank You. – Lani May 30 '18 at 22:57