title: Change the background color of a div after some interval
body: <p>Hey i am trying to change the background color of a div. I have written a script to change the background color of the body. The code is below</p>
  
  <pre><code>&lt;script&gt;
  colors = new Array('black', 'red', 'green');
  function annoyingEffect(tic){
  tic %= colors.length;
  document.bgColor = colors[tic];
  setTimeout("annoyingEffect("+(tic+1)+")", 2000);}
  &lt;/script&gt;
  &lt;body onload="annoyingEffect(0)"&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p>But if i try to add a div and insert the onload="annoyingEffect(0)" function inside it, it doesn't work. What I'm i missing?</p>