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
Post a Comment