javascript - Show and hide a div every 1s -


hi want show div 1s , hide 1s , loop code :

<div>flashing</div>      <script>         $(document).ready(function(){         hide();          function show(){           settimeout(function(){             $('div').show();           }, 2000);           hide();         }          function hide(){           settimeout(function(){             $('div').hide();           }, 2000);           show();         }       });     </script> 

but browser give me error: error:

uncaught rangeerror: maximum call stack size exceeded

you show , hide function call not in async part of function, resulting infinite loop. put call inside timer event :

  $(document).ready(function(){     hide();      function show(){       settimeout(function(){         $('div').show();         hide();       }, 2000);     }      function hide(){       settimeout(function(){         $('div').hide();         show();       }, 2000);     }   }); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -