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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -