View Single Post
Old 12-03-2012, 11:06 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
In any case, the code is horribly over-complex and could and should be simplified:
Code:
<html>
<body>
<div id="agent1">blah</div>
<div id="agent2">bleh</div>

<script type="text/javascript">
(
  function()
  {
     function blink( )
     {
          for ( var b = 1; b < 9999; ++b )
          {
              var div = document.getElementById("agent" + b )
              if ( div == null ) return;
  
              div.style.visibility = ( div.style.visibility == "hidden" ) ? "visible" : "hidden";
          }
      }

      setInterval( blink, 3000 );
  }
)();
</script>
</body>
</html>
Now it works with any number of "agentNN" divs (or spans or whatever) *and* with any initial visibility per agentNN (provided the style is code inline).

That is, you could add
Code:
    <span id="agent3" style="visibility: hidden;">wowser!</span>
And it would autmatically be blinked, as well, but in opposition to the blinks for agent1 and agent2, as given.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote