Changing src after 3 seconds
<p>I am trying to change the src attribute of an image with the class of "bg" after 3 seconds on a loop. It goes from "bg1.jpg" to "bg5.jpg". For some reason my code is not working and I am not getting any errors. </p>

<pre><code>$(document).ready(function(){

var $bg = $('.bg');

function bgChange() {
  var i = 1;
  while ( i &lt; 6 ) {
    var background = '&lt;?php echo $siteroot; ?&gt;/img/bg' + i + '.jpg';
    setTimeout($bg.attr('src', background), 1000);
    i++;
    if ( i === 5 ) {
      i = 1;
    }
  }
}

bgChange();
//------------------------------------
});
</code></pre>