javascript - Dynamic text in divs - how to get both to work on same page? -


i have 2 div tags (and maybe more) dynamic text. need them cycle in loop. got working 1 div tag. when apply same script second div tag, 1 works.

how both work @ same time on same page?

 <script type="text/javascript">  var text = ['foo', 'bar', 'baz'];  = 0,  $div = $('#div1');   setinterval(function ()  {  $div.fadeout(function ()  {     $div.text(text[i++ % text.length]).fadein(); }); }, 1000); </script>   <script type="text/javascript">  var text = ['foo', 'bar', 'baz'];  = 0,  $div = $('#div2');   setinterval(function ()  {  $div.fadeout(function ()  {     $div.text(text[i++ % text.length]).fadein(); }); }, 1000); </script> 

seperate script tags share same variables

<script type="text/javascript">     var text1 = ['foo', 'bar', 'baz'];     var i1 = 0,      var text2 = ['foo', 'bar', 'baz'];     var i2 = 0,     $(document).ready(function()     {         setinterval(function (){                 $("#div1").fadeout(function ()             {                 $("#div1").text(text[i1++ % text1.length]).fadein();             });         }, 1000);          setinterval(function (){             $("#div2").fadeout(function ()             {                 $("#div2").text(text[i2++ % text2.length]).fadein();             });         }, 1000);     }); </script> 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -