Here is the code:

$(document).ready(function(){ var pause = 5000; function removeFirstNewsTicket() { addLastNewsTicket(); } function addLastNewsTicket() { alert('123123'); } setInterval(removeFirstNewsTicket, pause); }); 

The question is, why does the alert work 2 times every 5 seconds? Generally shook me js. Explain somebody, please. Once and for all I want to deal with it = As a reward, I will give you as many points as you ask.

UPD1 makregister. Nothing helps. I tried to endure - all to no avail

UPD2 Alexander, did just that. Removed $ (document) .ready () - now everything is as it should.

UPD3 The css framework http://www.99lime.com/ was connected. After shutdown everything worked as it should. He also uses jQuery. Question: how to make the script work as it should through $ (document) .ready () and not be called 2 times with the above css-framework connected? For the decision - reward 500 mana points)

UPD4 I have one script is not connected twice. Apparently you have to deal with 99lime, since this is the case. Is it necessary to use ready () in general? What is the risk of refusing to use it?

  • 2
    [ One ] [1] the same. [1]: jsfiddle.net/bumbay/dHRP7 - Oleg
  • Is the script connected once? : D - neoascetic
  • one
    Everything is exactly [ one ] [1]. [1]: jsfiddle.net/bumbay/dHRP7/1 - Oleg
  • one
    make a stub: get a global variable, for example, assign the firstReady to it false, and change your f-cyb to function removeFirstNewsTicket () {if (firstReady) return; firstReady = true; addLastNewsTicket (); } something like this. - AlexAndR
  • one
    But there can not be a problem in different versions of jQuery ??? the library uses 1.6.4 as I understand it ... try using it too: ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js - AlexAndR

3 answers 3

Try renaming addLastNewsTicket to addLastNewsTicket1223113413413 , for example, you addLastNewsTicket1223113413413 know what can be called ...

In JS, with its lack of scopes, there can be anything.

Added from comment .

The error is simply most likely some kind of mockery ... and most likely not in the fragment that you sent. Try to disable jQuery to start ... For example:

 <html> <head> </head> <body> <script> var pause = 5000; function removeFirstNewsTicket() { addLastNewsTicket(); } function addLastNewsTicket() { alert('123123'); } setInterval(removeFirstNewsTicket, pause); </script> </body> </html> 
  • I do not know what the hell is going on with the hashcode. I can not leave comments. Alexander, besides this js-a code, there is no any at all. Only jQuery is connected and that's it. exec, there yes. 1 time is called. I have in any browser - 2 times. UPD1 makregister. Nothing helps. I tried to endure - all to no avail UPD2 Alexander, and did so. Removed $ (document) .ready () - now everything is as it should. Question: why didn’t he like $ (document) .ready () ?? - Vitaly Kustov
  • one
    Moved in response. - AlexAndR
  • I will add here, since the commentary is not added to the question itself (((if 2 versions of the library are used, then, in theory, anything could be ... the order of execution of the code and the scope of the variables (which, by the way, are most likely called in both versions) becomes unpredictable. By the way, you can try to just remove the jQuery link from your file, it will be pulled through the library anyway - AlexAndR
  • By the way, write to support 99lime, who knows, if not them, what is happening with them. - AlexAndR

Try to render the function definition to ready.

  var pause = 5000; function removeFirstNewsTicket() { addLastNewsTicket(); } function addLastNewsTicket() { alert('123123'); } $(document).ready(function(){ setInterval(removeFirstNewsTicket, pause); }); 

I do not see errors, it should work normally, the only thing you can do is check that the window is running, because we do not know how long the user will think until the alert closes, and at this time the interval is counting.

    Just like in a joke, where a man studied only taking off on an airplane, but he still doesn’t know anything about landing)) To stop this cycle, there is clearInterval () So stop them in the place where it is required.